#!/usr/bin/env bash
# PACIAE.sh is a part of the PACIAE event generator.
# Copyright (C) 2024 PACIAE Group.
# PACIAE is licensed under the GNU GPL v2 or later, see LICENSE for details.
# Open source: https://github.com/ArcsaberHep/PACIAE4
# Author: An-Ke Lei, October 2022 - January 2025.

# This is a toy SHELL-script to run PACIAE program.

#                                                By An-Ke at CCNU on 17/10/2022
#                                   Last updated by An-Ke at UiO  on 03/02/2025



################################################################################
################################################################################
################################################################################
###                                                                          ###
###   PPPPPPP       AAAAA       CCCCCCC    IIIIIII     AAAAA     EEEEEEEEE   ###
###   P      p     A     A     C       C      I       A     A    E           ###
###   P       p   A       A   C               I      A       A   E           ###
###   P      p    A       A   C               I      A       A   E           ###
###   PPPPPPP     AAAAAAAAA   C               I      AAAAAAAAA   EEEEEEEEE   ###
###   P           A       A   C               I      A       A   E           ###
###   P           A       A   C               I      A       A   E           ###
###   P           A       A    C       C      I      A       A   E           ###
###   P           A       A     CCCCCCC    IIIIIII   A       A   EEEEEEEEE   ###
###                                                                          ###
################################################################################
################################################################################
#                                                                              #
#                                                                              #
################################################################################
#                                                                              #
# This is a universal toy SHELL-script for PACIAE running on the normal LINUX  #
#   system in the personal-computer and the task submitting on SLURM (LSF,     #
#   PBS) scheduling systems in the computing cluster and the super-computer.   #
#                                                                              #
# This shell script will generate executable program, "usu.dat",               #
#   "pythia6_extra.cfg", "pythia8_extra.cfg", "Makefile" and an inner          #
#   "PACIAE_SIM.sh" shell script, then run / submit tasks automatically.       #
#                                                                              #
# A series of folders will be generated by "Makefile" to store different type  #
#   of files, including "src" (source folder, stores the source code files),   #
#   "bin" (binary folder, stores the binary executable files), "obj" (object   #
#   folder, stores the compiling intermediate files), "include" (include       #
#   folder, stores the header files), "lib" (library folder, stores the        #
#   libarary files), "log" (log record folder, stores the running informations #
#   if user has specified), "bak" (backup folder, stroes the backup files),    #
#   "doc" (document folder, stroes the program manual and other readable       #
#   documents), "etc" (etcetera folder, stores the configuration and other     #
#   files), "fig" (figure folder, stores figure files, free for user) and      #
#   "sim" (simulation folder, stroes the outputs of PACIAE simulation). The    #
#   PACIAE running folder with the name of collisions system will be also      #
#   generated in the "sim" folder for easier management.                       #
#                                                                              #
# It makes the (pseudo-)SPMD (single program, multiple data) possible to       #
#   achieve the (pseudo-)parallel running via a secondary SHELL-script file    #
#   "PACIAE_SIM.sh".                                                           #
# Total N events are split up to multiple separate (N/number_of_CPU) events    #
#   and run simultaneously on multiple processors with different input random  #
#   seed based on the real-time clock of the machine.                          #
# This random number generator seed is set in PACIAE internal code (main.f90). #
#                                                                              #
# One needs to note that it's just a "pseudo-parallism". In other words, this  #
#   script just performs PACIAE running one-by-one automatically instead of    #
#   manual runs. One also needs another program to aggregate and average all   #
#   the results needed after the entire PACIAE runnings finished. A simple     #
#   averaging program, independent of the PACIAE program, "Rms_analysis.f90"   #
#   was provided to do average over the result of "rms.out" the PACIAE         #
#   generated, which gives simple results and reports of the simulation.       #
#                                                                              #
# This script has been tested on WSL/UBUNTU-22.04 on PC, on SLURM on the       #
#   Norwegian Research Infrastructure Services Saga cluster (NRIS Saga, normal #
#   partition), and on LSF on the National SuperComputing Center in Shenzhen   #
#   (NSCCSZ, Gsx_normal partition).                                            #
################################################################################
#                                                                              #
# How to use:                                                                  #
#                                                                              #
#   1. First and formost, give this script file "executable permission" by     #
#        typing command "sudo chmod +x PACIAE.sh" (only once). In addition,    #
#        one needs "make" tool, "gfortran" and "g++"" compilers. Install them  #
#        using the command, for example on UBUNTU, "sudo apt install make".    #
#                                                                              #
#   2. Modify the variabls needed.                                             #
#        2.1 Modify the variables: the number of program-running ("n_run",     #
#              preferably not larger than the total number of CPU cores of the #
#              computer), the number of events per program-running ("n_eve"),  #
#              and other main setups of incident particles and collisions etc. #
#            Here, some variables are aliases for the ones in "usu.dat".       #
#            More detailed setups can be modified in the closely following     #
#              "usu.dat", "pythia6_extra.cfg" and "pythia8_extra.cfg"          #
#              directly. Search keywords "usu.dat" etc. to find them.          #
#           The parameters include two parts mainly: PACIAE-related and        #
#              PYTHIA-related.                                                 #
#        2.3 On SLURM/LSF/PBS scheduling systems in the computing cluster and  #
#              the super-computer. One needs specify the additional statements #
#              of the settings at the lines of "Scheduling System Setting"     #
#              (#SBATCH, #APP_NAME, #PBS, ...).                                #
#                                                                              #
#   3. Execution.                                                              #
#        On the normal LINUX, run this script by typing command                #
#          "./PACIAE.sh".                                                      #
#        Furthermore, the command                                              #
#          "time ./PACIAE.sh | tee $(date "+%Y%m%d%H%M%S").log",               #
#          will stores the screen information to a log file.                   #
#                                                                              #
#                                           By An-Ke Lei at CCNU on 17/10/2022 #
#                                                                              #
#                              Last updated by An-Ke Lei at UiO  on 11/11/2024 #
################################################################################
################################################################################
################################################################################



# Gets and prompts the current date and time.
current_date_and_time=$(date "+%Y%m%d%H%M%S")
echo -e "\nNow is $(date +"%Y-%m-%d %T")"



################################################################################
#   Modify the following statements as needed.                                 #
################################################################################



################################################################################
################################################################################
###############             Scheduling System Setting             ##############
# If you do not use the scheduling system (normally on the computing cluster
#   and the super-computer), just ignore this part.
# Flag of running system. LINUX/SLURM/LSF/PBS.
FLAG_SYSTEM=LINUX
# FLAG_SYSTEM=SLURM
# FLAG_SYSTEM=LSF
# FLAG_SYSTEM=PBS
#
# Example statements for the SLURM scheduling system:
read -d "" SCHEDULE_SYSTEM << SCHEDULE_SYSTEM_BLOCKTEXT
#SBATCH --account=nn9773k"
#SBATCH --partition=normal"
#SBATCH --job-name=PACIAE_${current_date_and_time}"
#SBATCH --time=1:00:00   ## Maxmum 168:00:00 in Saga."
#SBATCH --mem-per-cpu=500M"
SCHEDULE_SYSTEM_BLOCKTEXT
# Adds statements above the "SCHEDULE_SYSTEM_BLOCKTEXT" line.
###############             Scheduling System Setting             ##############
################################################################################
################################################################################



################################################################################
################################################################################
####################      Variable's alias for usu.dat      ####################

#******************************************************************************#
# Setups of the program-running.
# Total number of events in all program-runnings = n_run * n_eve.
n_run=45    # Number of program-running tasks.
i_begin=46   #Lei_debug
n_eve=1000000   # neve: number of events per program-running task.
n_out=10000    # (D=neve/10) nout: output the event logs per nout events.
n_osc=0     # (D=0) nosc: = 0, no OSCAR output (oscar.out).
            #             = 1, OSCAR1997A (final_id_p_x, final output).
            #                  Space-time information at final evolution time.
            #             = 2, OSCAR1999A (full_event_history)
            #                  Space-time information at final evolution time.
            #             = 3, OSCAR1997A (final_id_p_x, final output).
            #                  Space-time at particle's own freeze-out time.
            #             = 4, OSCAR1999A (full_event_history)
            #                  Space-time at particle's own freeze-out time.
i_random=1  # (D=1) adj1(26): random generator seed in PYTHIA.
            #        =0, default PACIAE seed (20240116), can be used for debug.
            #        =1, seed from the real-time system clock (h-min-s-ms).
            #        >1, sets seed as "i_random".
i_stage=4   # (D=4) adj1(40), simulation stop point:
            #                 =1, stops simulation after parini.
            #                  2, ... parcas.
            #                  3, ... hadronization with coal from parini.
            #                  4, ... entire simulation.

#******************************************************************************#
# Setups of the simulation framework (mode).
i_sim_mode=9    # (D=6) i_mode, simulation mode:
                #              =1, PACIAE low-energy hadronic simulation,
                #                  E_CMS < 3 GeV (A).
                #              =2, PYTHIA-like pure hadronic simulation based
                #                  on PYTHIA 6 (B_PY6).
                #              =3, PACIAE parton-hadron cascade simulation based
                #                  on PYTHIA 6 (C_PY6).
                #              =4, PACIAE experimental mode for pA/Ap simulation
                #                  based on PYTHIA 6 (D).
                #              =5, PYTHIA-like pure hadronic simulation based
                #                  on PYTHIA 8 (B_PY8).
                #              =6, PACIAE parton-hadron cascade simulation based
                #                  on PYTHIA 8 (C_PY8).
                #              =7, dummy now.
                #              =8, PYTHIA-like pure hadronic simulation based
                #                  on PYTHIA8/Angantyr (B_ANG).
                #              =9, PACIAE parton-hadron cascade simulation based
                #                  on PYTHIA8/Angantyr (C_ANG).

#******************************************************************************#
# Setups of the incident particles.
KF_proj=2212   # KF_proj: PDG id code (KF code) of the projectile.
KF_targ=2212   # KF_targ: PDG id code (KF code) of the target.
                     # E.g.
                     #   subatomic particles:
                     #       p: 2212,  pbar: -2212;
                     #       n: 2112,  nbar: -2212;
                     #     pi+: 211,    pi-: -221;
                     #      e-: 11,      e+: -11;
                     #    nu_e: 12, nu_ebar: -12;
                     #      ...
                     #   nuclei:
                     #      197Au: 1000791970; 208Pb: 1000822080;
                     #       96Zr: 1000400960;  96Ru: 1000440960;
                     #         2H: 1000010020;   4He: 1000020040;
                     #        12C: 1000060120;   16O: 1000080160;
                     #       63Cu: 1000290630; 107Ag: 1000471070;
                     #      129Xe: 1000541290;  238U: 1000922380;
                     #      ...

#******************************************************************************#
# Setups of the collision.
b_min=0     # (D=0.)  bmin, min impact parameter.
b_max=5    # (D=20.) bmax, max impact parameter.
b_samp=3    # (D=2) psno, b parameter sampling method for [b_min,b_max].
            #             =0, fixed b (=bmin), zero b-angle
            #              1, systematic sampling, zero b-angle
            #              2, random sampling, zero b-angle
            #            For Angantyr mode,
            #             =3, as = 0, but random b-angle
            #              4, as = 1, but random b-angle
            #              5, as = 2, but random b-angle
            #              6, for Angantyr ion mode, original Gaussian sampling.
            #                 This option will generate weighted events and set
            #                 a large range of 0 < b < 20+ fm automatically.
i_frame=1   # (D=1) ifram, collision frame: 0 = fixed target with a incident pz;
            #                               1 = collider with CMS energy (win);
            #                               2 = back-to-back beams with
            #                                   +Z energy_A and -Z energy_B.
            #                                   This option could be used for
            #                                   the fixed-target (e=0) or the
            #                                   asymmetric collision systems
            #                                    like pA/Ap in the Lab frame.
energy=7000   # (GeV) win/energy_A, the incident momentum +pz if i_frame = 0;
              #                    the CMS energy SQRT(s)    if i_frame = 1;
              #                    the energy of +Z beam     if i_frame = 2.
energy_B=0      # (GeV) energy_B, energy of -Z beam  if i_frame = 2.
                #                 This variable can be used for the asymmetric
                #                 colliding system like pA/Ap collsions in the
                #                 Lab frame if i_frame = 2, e.g.
                #                 LHC p+Pb at a CMS energy
                #                  SQRT(s_NN) = 5.02 TeV:
                #         energy_A = 4.0 TeV, energy_B = 1.575 TeV, i_frame = 2;
                #                  SQRT(s_NN) = 8.16 TeV:
                #         energy_A = 6.5 TeV, energy_B = 2.561 TeV, i_frame = 2.
i_channel=0 # (D=10) nchan, collision channel for non-A simulation frameworks:
             #                =0, inelastic (INEL).
             #                 1, Non Single Difractive (NSD).
             #                 2, Drell-Yan process.
             #                 3, J/psi production (color singlet).
             #                 4, heavy-flavor production.
             #                 5, direct photon.
             #                 6, soft only.
             #                 7, W+/- production.
             #                 8, PYTHIA default hard QCD (MSEL = 1).
             #                 9, Z0 production.
             #                10, inelastic, non-diffractive (minimum-bias).
             #                <0, -MSEL defined in PYTHIA 6.
             #               -61, NRQCD charmonium production.
             #               -62, NRQCD bottomonium production.
             #               -63, NRQCD onia production (charm- and bottom-).
             #            others, requires user to specify in the program
             #                    or "pythia6_extra.cfg" /
             #                       "pythia8_extra.cfg" files.
# Setups of the hadronization (string fragmentation:SFM; coalescence: Coal).
i_hadronization=0   # (D=0) adj1(12), model for hadronization
                    #                 =0, string fragmentation (SFM)
                    #                 =1, Monte-Carlo coalescence (Coal)
                    #                 =2, Coal with gluon splitting and
                    #                     deexcitation before parcas (same as
                    #                     =1 plus kjp22=2)
                    #                 =3, SFM with gluon splitting and
                    #                     deexcitation before parcas
                    #                 Subclass please see "kjp22".


#******************************************************************************#
#****************             Setups of PYTHIA                 ****************#
#****************   (D=PY6 PY8): default value for PYTHIA6/8   ****************#
#
# Extra parameters and switches of PYTHIA 6 & 8 please specify on the following
#   "pythia6_extra.cfg" and "pythia8_extra.cfg" parts directly.
#
k_PYTHIA=1  # (D=1. 1.) adj1(10), i.e. PARP(31) in PYTHIA: K factor multiplying
            #            the differential cross sections for hard parton-parton
            #            process (multiple parton interaction) in PYTHIA.
a_lund=0.68 # (D=0.35 0.68) adj1(6), i.e. PARJ(41) in PYTHIA: a in Lund
            #                                     string fragmentation function.
b_lund=0.98 # (D=0.8  0.98) adj1(7), i.e. PARJ(42) in PYTHIA: b in Lund ... .
pT_width=0.335  # (D=0.33 0.335) adj1(34), i.e. PARJ(21) in PYTHIA: width of pT
                #                               sampling (sigma) in Lund ... .
i_fragment_mode=5   # (D=5 5) kjp22, fragmentation mode.
                    #                =1, fragmentation string by string, with
                    #                    the single string structure induced
                    #                    variable string tension and PARJ(1) etc
                    #                =2, fragmentation string by string, with
                    #                    the multiple string interaction induced
                    #                    variable string tension and ...
                    #                =3, fragmentation string by string, with
                    #                    the (single string structure + multiple
                    #                    tring interaction) induced string
                    #                    tension and ...
                    #                =4, fragmentation of all strings at once
                    #                    with default string tension and ...
                    #                =5, fragmentation NN pair by pair, with
                    #                    default string tension and ...
                    #              For PYTHIA 8 only:
                    #                =6, fragmentation by the Rope Hadronization
                    #                     with Flavour Ropes.
                    #                =7, fragmentation by the Rope Hadronization
                    #                    with String Shoving.
                    #                =8, fragmentation by the Rope Hadronization
                    #                    with Flavour Ropes + String Shoving.
                    #                =9, Thermodynamical String Fragmentation.
i_color_reconnection=8  # (D=8 8) i_color_reconnection, i.e. MSTP(95) in PYTHIA:
                        #         selection of color-reconnection model.
                        #   = 0, no color-reconnection.
                        # For PYTHIA 6:
                        #   "S": Seattle model, "P": Paquis model.
                        #   = 1, Old cut-and-paste style CR, handled in PYMIHK.
                        #   = 2, Annealing Type I(no gg loops); hadron-hadron.
                        #   = 3, Annealing Type I(no gg loops); all beams.
                        #   = 4, Annealing Type II(gg loops)  ; hadron-hadron.
                        #   = 5, Annealing Type II(gg loops)  ; all beams.
                        #   = 6, Annealing Type S             ; hadron-hadron.
                        #   = 7, Annealing Type S             ; all beams.
                        #   = 8, Annealing Type P             ; hadron-hadron.
                        #   = 9, Annealing Type P             ; all beams.
                        #   =11, Soft Color Interaction (SCI model).
                        #   =12, SCI without diffraction (no inter-remnant CR).
                        #   =13, Generalized Area Law (GAL model).
                        #   =14, GAL without diffraction (no inter-remnant CR).
                        # For PYTHIA 8:
                        #   <15, The MPI-based original PYTHIA 8 scheme (MPI-CR)
                        #   =15, The new more QCD based scheme(QCD-, QCD-BLC-CR)
                        #   =16, The new gluon-move model.
                        #   =17, The SK I e+e- CR model.
                        #   =18, The SK II e+e- CR model.


#******************************************************************************#
#****************               Setups of PACIAE               ****************#
#
# More options could be modified on the following "usu.dat" part directly.
#
##---------------               Setups of parcas               ----------------#
# Setups of the partonic cascade/rescattering (parcas).
k_parcas=1      # (D=1.) adj1(1), K factor multiplying on the differential
                #                  cross-section in parton cascade.
                #                 =0, without parton cascade.
#
##---------------           Setups of hadronization            ----------------#
### Setups of the coalescence model (Coal).
### NOTE that the following "coal" parameters works when "i_hadronization=1/2/3"
i_coal_mode=5   # (D=5) kjp22, coalescence mode
                #              =1, mode 1, gluon splitting and energetic quark
                #                  deexcitation AFTER partonic rescattering,
                #                  via the traversal coalescence.
                #              =2, mode 2, gluon splitting and energetic quark
                #                  deexcitation BEFORE partonic rescattering.
                #                  via the traversal coalescence.
                #              =3, mode 3, as = 1, but only quark deexcitation.
                #              =4, mode 4, as = 2, but only quark deexcitation.
                #              =5, as = 2, to keep the consistency of "kjp22".
                #              New coalescence scheme:
                #              =6-9, mode 6-9, as = 1-4, but the random coal.
i_deex=1    # (D=1) i_deex, the deexcitation (gluon splitting) scheme in coal
            #               =1, light-cone momentum scheme.
            #               =2, energy scheme.
            #               =3, longitudinal momentum pz scheme.
i_deex_function=5   # (D=0) adj1(29), Choice of the deexcitation function i.e.
                    #                 how large a fraction of the light-cone
                    #                 /energy/pz available a newly-created
                    #                 qqbar takes.
                    #                =0, random z for coal.
                    #                =1, Lund symmetric fragmentation function.
                    #                =2, Field–Feynman(FF) + Peterson/SLAC(PS).
                    #                =3, Lund + Peterson/SLAC.
                    #                =4, Lund + Bowler.
                    #                =5, as = 4, but interpolate for c and b.
a_Lund_coal=0.68       # (D=0.68) adj1(8), see PYTHIA part above.
b_Lund_coal=0.98       # (D=0.98) adj1(9), See PYTHIA part above.
pT_width_coal=0.45     # (D=0.45) adj1(35), See PYTHIA part above.
a_FF=0.77              # (D=0.77) a_FF, parameter for uds in FF.
aPS_c=0.05             # (D=0.05) aPS_c, parameter for c in PS.
aPS_b=0.005            # (D=0.005) aPS_b, parameter for b in PS.
prob_ratio=(1 1 0.225 0 0 0)   # (D= 1 1 0.225 0 0) Probability ratio of
                               #  u:d:s:c:b:t for qqbar sampling.
ratio_B_to_M=0.08   # (D=0.08) bmrat, parameter related to the ratio of
                    #                 baryons to mesons.
e_deex=1.5          # (D=1.5) adj1(17), quark deexcitation threshold energy.
e_split=0.66        # (D=0.66) adj1(39), gluon splitting threshold energy.
n_deex_step=1       # (D=1) n_deex_step, the number of deexcitation steps per q.
i_phase_constraint=0    # (D=0) adj1(21), phase-space constraint in coalescence.
                        #                =0, without
                        #                =1, with complete phase-space
                        #                =2, with position-space only
                        #                =3, with momentum-space only
#
##---------------               Setups of hadcas               ----------------#
# Setups of the hadronic cascade/rescattering (hadcas).
i_hadcas=0  # (D=1) kjp21, = 0, without hadron cascade;
            #                1, with PACIAE built-in hadronic rescattering.
#
##---------------            Setups of A-framework             ----------------#
# Setups for A-framework.
prob_Delta_decay=0.9    # (D=0.9) decpro, Delta decay probability in A-framework
x_ratio=0.85   # (D=0.85) x_ratio, ratio of the inela. cross section to
               #              the total cross section of hadron-hadron
               #              collisions in A-framework and hadcas.
               #              = 0.85 for the high-energy B-, C & D-framework
               #              = 0.1 for the A-framework (E_CMS < 3 GeV)


#******************************************************************************#
#******************            Setups of Analysis            ******************#
n_particle_specie=100 # (D=20) ispmax, number of particle species to be counted.
n_distribution=7     # (D=7) isdmax, number of statistical distributions.
n_kine_cut=2         # (D=2) iflmax, number of kinematic cut (default pT, y/eta)
n_bin_hist=40        # (D=40) n_bin_hist, number of bins in histograms.
# The "asd(i)" in usu.dat, i.e. bin width.
bin_1=0.5          # (D=0.35) y bin width (dN/dy VS. y)
bin_2=1          # (D=0.5)  pT bin width (inv. pT, 1/pT*dN/dpT VS. pT)
bin_3=0.5          # (D=0.35) eta bin width (dN/deta)
bin_4=0.5           # (D=0.5)  mT bin width (inv. mT, 1/mT*dN/dmT VS. mT)
bin_5=2.5           # (D=25)   multiplicity bin width (dNev/dmult VS. mult)
bin_6=1          # (D=0.5)  pT bin width (dN/dpT VS. pT)
bin_7=2.5           # (D=25)   multiplicity bin width (<pT> VS. mult)
i_y_or_eta=1    # (D=1) i_y_or_eta, selects y or eta in partial-space statistics.
                #       = 0 , y
                #       = 1 , eta
# For 20 particles, use the same cuts.
rap_low=-0.8    # (D=-1)  afl(*,1,1), y/eta lower cut
rap_upp=0.8     # (D= 1)  afl(*,1,2), y/eta upper cut
pT_low=0.15     # (D=0.)  afl(*,2,1), pT lower cut
pT_upp=999.     # (D=50.) afl(*,2,2), pT upper cut
#Lei_debug------
rap_low_c=-0.5    # (D=-1)  afl(*,1,1), y/eta lower cut
rap_upp_c=0.5     # (D= 1)  afl(*,1,2), y/eta upper cut
pT_low_c=0.000001     # (D=0.)  afl(*,2,1), pT lower cut
pT_upp_c=999.     # (D=50.) afl(*,2,2), pT upper cut
#Lei_debug------


#******************************************************************************#
# The following lines are not required to be changed.
if [[ "${i_hadronization}" -gt "3" ]]; then
    i_hadronization=0
fi
if [[ "${i_hadronization}" -eq "1" || "${i_hadronization}" -eq "2" ]]; then
    i_fragment_mode=${i_coal_mode}
    if [[ "${i_hadronization}" -eq "2" ]]; then
        i_hadronization=1
        i_fragment_mode=2
    fi
fi
#
####################      Variable's alias for usu.dat      ####################
################################################################################
################################################################################


# More options could be modified on the following "usu.dat" directly.


################################################################################
################################################################################
####################               usu.dat              ########################
read -d "" USU_DAT << USU_DAT_BLOCKTEXT
${n_eve},${n_out},${n_osc}        ! neve,nout,nosc
${KF_proj},${KF_targ}     ! KF_proj,KF_targ. E.g. e-: 11; e+: -11; p: 2212; n: 2112; Au(79,197): 1000791970; Pb(82,208): 1000822080.
${i_sim_mode},${i_frame},${i_channel}         ! i_mode,ifram,nchan
${energy},${energy_B}         ! win(energy_A),energy_B
${b_min},${b_max},${b_samp},10     ! bmin,bmax,psno,nmax
${i_hadcas},${x_ratio},${prob_Delta_decay}    ! kjp21,x_ratio,decpro
${n_particle_specie},${n_distribution},${n_kine_cut},${n_bin_hist},${i_y_or_eta}   ! ispmax,isdmax,iflmax,n_bin_hist,i_y_or_eta
0,0,0,0,0,0,0,0,0,0   ! KF code of particles not to decay (1-10)
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0   ! KF code of particles not to decay (11-ispmax)
211,-211,321,-321,130,310,2212,-2212,2112,-2112   ! KF code of particles to be analyzed online (1-10)
3122,-3122,3112,-3112,3222,-3222,3312,-3312,3322,-3322,   3334,-3334,443,100443,553,100553,4122,-4122,4112,-4112,   4212,-4212,4222,-4222,4132,-4132,4232,-4232,4412,-4412,   4422,-4422,4332,-4332,4432,-4432,4444,-4444,411,-411,   421,-421,431,-431,413,-413,423,-423,433,-433,   4122,-4122,4112,-4112,4212,-4212,4222,-4222,4132,-4132,   4232,-4232,4412,-4412,4422,-4422,4332,-4332,4432,-4432,   4444,-4444,411,-411,421,-421,431,-431,413,-413,   423,-423,433,-433,4122,4112,4132,4232,4412,421   ! KF code of particles to be analyzed online (11-ispmax)
${bin_1},${bin_2},${bin_3},${bin_4},${bin_5},${bin_6},${bin_7}  ! ( asd(i), i=1,isdmax )
${rap_low},${rap_upp}                        ! afl(1,1,1), afl(1,1,2)
${pT_low},${pT_upp}                          ! afl(1,2,1), afl(1,2,2)
${rap_low},${rap_upp}                        ! afl(2,1,1), afl(2,1,2)
${pT_low},${pT_upp}                          ! afl(2,2,1), afl(2,2,2)
${rap_low},${rap_upp}                        ! afl(3,1,1), afl(3,1,2)
${pT_low},${pT_upp}                          ! afl(3,2,1), afl(3,2,2)
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}   ! 11
${pT_low},${pT_upp}     ! 11
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}
${pT_low},${pT_upp}
${rap_low},${rap_upp}                        ! afl(ispmax,1,1), afl(ispmax,1,2)
${pT_low},${pT_upp}                          ! afl(ispmax,2,1), afl(ispmax,2,2)
${rap_low},${rap_upp}   ! 21
${pT_low},${pT_upp}     ! 21
${rap_low},${rap_upp}                     ! afl(ispmax,1,1), afl(ispmax,1,2)
${pT_low},${pT_upp}                       ! afl(ispmax,2,1), afl(ispmax,2,2)
${rap_low_c},${rap_upp_c}   ! 23, heavy-flavor, J/psi
${pT_low_c},${pT_upp_c}     ! 23, heavy-flavor, J/psi
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 27, Lambda_c+
${pT_low_c},${pT_upp_c}     ! 27, Lambda_c+
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 31
${pT_low_c},${pT_upp_c}     ! 31
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 41
${pT_low_c},${pT_upp_c}     ! 41
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 51
${pT_low_c},${pT_upp_c}     ! 51
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 61
${pT_low_c},${pT_upp_c}     ! 61
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 71
${pT_low_c},${pT_upp_c}     ! 71
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 81
${pT_low_c},${pT_upp_c}     ! 81
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 91
${pT_low_c},${pT_upp_c}     ! 91
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}
${pT_low_c},${pT_upp_c}
${rap_low_c},${rap_upp_c}   ! 100
${pT_low_c},${pT_upp_c}     ! 100
0.00001,2               ! ddt,i_mm
0,1,0,1                 ! iparres,i_inel_proc,i_time_shower,i_diquark
1.2,0.,0.5,10000.       ! para(7),ttaup,taujp,para(10)
1,1                     ! i_sigma_AQM,kjp20
0.,40.,25.,21.,10.,2.   ! para1_1,para1_2,para(2),para(3),para(4),para(5)
7.2,4.,14.,8.           ! para(13),para(14),para(15),para(16)
${k_parcas},0.47,0.4,1000,1,${a_lund},${b_lund},${a_Lund_coal},${b_Lund_coal},${k_PYTHIA}   ! adj1(1)-adj1(10)
0.1,${i_hadronization},0,0,1.,1,${e_deex},0,0.03,3       ! adj1(11)-adj1(20)
${i_phase_constraint},4.,1,0.15,0.4,${i_random},0.,10000.,${i_deex_function},1           ! adj1(21)-adj1(30)
0,0,0,${pT_width},${pT_width_coal},0,100.,3.,${e_split},${i_stage}           ! adj1(31)-adj1(40)
${i_fragment_mode},2,2,${i_color_reconnection},0                    ! kjp22,kjp23,kjp24,i_color_reconnection,i_tune
0.,0.,1.,0.2,0.05            ! parecc,smadel,cp0,cr0,seco
${i_deex},${n_deex_step},1,0                      ! i_deex,n_deex_step,i_pT_coal,i_pT_endpoint
${a_FF},${aPS_c},${aPS_b},${ratio_B_to_M}         ! a_FF,aPS_c,aPS_b,bmrat
${prob_ratio[0]},${prob_ratio[1]},${prob_ratio[2]},${prob_ratio[3]},${prob_ratio[4]},${prob_ratio[5]}                ! prob_ratio_q
USU_DAT_BLOCKTEXT
# Modifys parameters manually above "USU_DAT_BLOCKTEXT" line.
echo "${USU_DAT}" > usu.dat
####################               usu.dat              ########################
################################################################################
################################################################################


# Extra parameters and switches of PYTHIA 6 & 8 please specify on the following
#   "pythia6_extra.cfg" and "pythia8_extra.cfg" directly.


################################################################################
################################################################################
################              pythia6/8_extra.cfg              #################
# pythia6_extra.cfg
read -d "" PY6_CFG << PY6_CFG_BLOCKTEXT
!!==============================================================================
!! 1. You can add extra PYTHIA 6 parameters and switches in this file directly.
!! 2. Note that settings here will mask PYTHIA6-related ones in "usu.dat".
!! 3. Do not use separate blank lines and separate comment lines beginning with
!!    non-'!' !
!!
!! Example statements:
!!  MSUB(68) = 1        !! Opens Hard QCD process g + g -> g + g.
!!  MDCY(C-411,1) = 0   !! Prohibits the decay of D- particle.
!!
!! More parameters and switches please refer to the PYTHIA 6.4 manual
!!  [JHEP 05 (2006) 026].
!!==============================================================================
!!
CKIN(3) = 1.0   ! (D=0.0 GeV) The lower limit of allowed pT for hard processes.
PARJ(1) = 0.087 ! (D=0.087) Diquark suppression
PARJ(2) = 0.190 ! (D=0.190) Strangeness suppression
PARJ(3) = 0.950 ! (D=0.950) Strange diquark suppression
PY6_CFG_BLOCKTEXT
# Adds statements above the "PY6_CFG_BLOCKTEXT" line.
echo "${PY6_CFG}" > pythia6_extra.cfg

# pythia8_extra.cfg
read -d "" PY8_CFG << PY8_CFG_BLOCKTEXT
//==============================================================================
// 1. You can add extra PYTHIA 8 parameters and switches in this file directly.
// 2. Note that settings here will mask PYTHIA8-related ones in "usu.dat".
// 3. You can use separate blank lines and separate comment lines beginning with
//   non-alphanumeric character, like '#', '!' and '/' .
//
// 4.1 Example statements 1:
//  HardQCD:gg2gg = on      // Opens Hard QCD process g + g -> g + g.
//  -411:mayDecay = false   // Prohibits the decay of D- particle.
//
// 4.2 Example statements 2:
//  Add new particles/nuclei to PYTHIA8/Angantyr. Tails can be omitted.
//   id:all = name antiName spinType chargeType colType m0 mWidth mMin mMax tau0
//   1000400960:all = 96Zr 96Zrbar
//   1000440960:all = 96Ru 96Rubar
//
// More parameters and switches please refer to the PYTHIA 8 online manual
//  [https://pythia.org//latest-manual/Welcome.html].
//==============================================================================

PhaseSpace:pTHatMin = 1.0     // (D=0.0 GeV) The minimum invariant pT.
StringFlav:probQQtoQ = 0.081  // (D=0.081) Diquark suppression
StringFlav:probStoUD = 0.217  // (D=0.217) Strangeness suppression
StringFlav:probSQtoQQ = 0.915 // (D=0.915) Strange diquark suppression

// HardQCD:hardccbar = on
# HadronLevel:Rescatter = on

// Angantyr p-Pb at 4000 + 1590 GeV.
# HeavyIon:SigFitNGen = 0
# HeavyIon:SigFitDefAvNDb = 0.95
# HeavyIon:SigFitDefPar = 1.53,9.56,0.28

# // Angantyr Pb-Pb at 5020 GeV.
# HeavyIon:SigFitNGen = 0
# HeavyIon:SigFitDefAvNDb = 0.96
# HeavyIon:SigFitDefPar = 1.51,9.29,0.28

# // Angantyr Pb-Pb at 13000 GeV.
# HeavyIon:SigFitNGen = 0
# HeavyIon:SigFitDefAvNDb = 1.02
# HeavyIon:SigFitDefPar = 1.67,13.21,0.27

// Angantyr Pb-Pb unit weight.
# HeavyIon:forceUnitWeight = on
# HeavyIon:bWidth = 1.0
# HeavyIon:bWidthCut = 5.0

// Nuclear modified PDF.
# PDF:useHardNPDFA = on
# PDF:useHardNPDFB = on

# // QCD-CR tune
# //
# BeamRemnants:remnantMode = 1
# BeamRemnants:saturation = 5
# //
# ColourReconnection:mode = 1
# ColourReconnection:allowDoubleJunRem = off
# ColourReconnection:allowJunctions = on
# StringZ:aLund = 0.36
# StringZ:bLund = 0.56
# StringFlav:probQQtoQ = 0.078
# StringFlav:ProbStoUD = 0.2
# StringFlav:probQQ1toQQ0join = 0.0275,0.0275,0.0275,0.0275
# // mode 0
# # ColourReconnection:timeDilationMode = 0
# # MultiPartonInteractions:pT0Ref = 2.12
# # ColourReconnection:m0 = 2.9
# # ColourReconnection:junctionCorrection = 1.43
# // mode 2
# # ColourReconnection:timeDilationMode = 2
# # MultiPartonInteractions:pT0Ref = 2.15
# # ColourReconnection:m0 = 0.3
# # ColourReconnection:junctionCorrection = 1.20
# # ColourReconnection:timeDilationPar = 0.18
# // mode 3
# # ColourReconnection:timeDilationMode = 3
# # MultiPartonInteractions:pT0Ref = 2.05
# # ColourReconnection:m0 = 0.3
# # ColourReconnection:junctionCorrection = 1.15
# # ColourReconnection:timeDilationPar = 0.073

// SC-CR
//
BeamRemnants:remnantMode = 1
BeamRemnants:saturation = 5
//
ColourReconnection:mode = 1
ColourReconnection:allowDoubleJunRem = off
ColourReconnection:allowJunctions = on
StringZ:aLund = 0.36
StringZ:bLund = 0.56
StringFlav:probQQtoQ = 0.078
StringFlav:ProbStoUD = 0.2
StringFlav:probQQ1toQQ0join = 0.0275,0.0275,0.0275,0.0275   ! New by Christian
# 4:m0 = 1.3   ! New by Christian
# -4:m0 = 1.3   ! New by Christian
# 5:m0 = 4.2   ! New by Christian
# -5:m0 = 4.2   ! New by Christian
# ColourReconnection:heavyLambdaForm = 2   # 0: no; 1: junc c, b; 2: all c, b.
# StringFlav:ProbStoUD = 0.4   ! New by Christian
//
ColourReconnection:reconnect = off
ColourReconnection:forceHadronLevelCR = on
PartonVertex:setVertex = on
ColourReconnection:timeDilationMode = 0
MultiPartonInteractions:pT0Ref = 2.37
ColourReconnection:m0 = 1.05
ColourReconnection:junctionCorrection = 1.37
ColourReconnection:dipoleMaxDist = 0.5
HISigmaDiffractive:mode = 0
HISigmaDiffractive:PomFlux = 3
HISigmaDiffractive:PomFluxEpsilon = force -0.04
HIBeamRemnants:remnantMode = 1
HIBeamRemnants:Saturation = 5
BeamRemnants:beamJunction = on
HIBeamRemnants:beamJunction = on

PY8_CFG_BLOCKTEXT
# Adds statements above the "PY8_CFG_BLOCKTEXT" line.
echo "${PY8_CFG}" > pythia8_extra.cfg
################              pythia6/8_extra.cfg              #################
################################################################################
################################################################################










################################################################################
#   The following statements are not required to be modified.                  #
################################################################################










################################################################################
####################                                    ########################
####################        Annotation of usu.dat       ########################
####################                                    ########################
################################################################################
echo "" >> usu.dat
read -d "" USU_ANNO << USU_ANNO_BLOCKTEXT
######################        Annotation of usu.dat         ####################
# neve,nout,nosc (D=xxx, xxx/10, 0)
#  neve: number of events to be generated
#  nout: output the event logs (main.out, rms.out) per nout events
#  nosc: OSCAR standard output (oscar.out)
#        = 0, no OSCAR output, see subroutine oscar
!        = 1, OSCAR1997A (final_id_p_x, just PACIAE final output).
!             Space-time information at the final evolution time.
!        = 2, OSCAR1999A (full_event_history)
!             Space-time information at the final evolution time.
!        = 3, OSCAR1997A (final_id_p_x, just PACIAE final output).
!             Space-time information at particle's own freeze-out time.
!        = 4, OSCAR1999A (full_event_history)
!             Space-time information at particle's own freeze-out time.
#
# KF_proj,KF_targ (D=1000791970, 1000791970)
#  KF_proj: PDG id (KF code) of the projectile
#  KF_targ: PDG id (KF code) of the target
#           E.g.
#             subatomic particles:
#                 p: 2212,  pbar: -2212;
#                 n: 2112,  nbar: -2212;
#                e-: 11,      e+: -11;
#              nu_e: 12, nu_ebar: -12;
#                ...
#             nuclei: (100ZZZAAA0)
#                197Au: 1000791970; 208Pb: 1000822080;
#                 96Zr: 1000400960;  96Ru: 1000440960;
#                   2H: 1000010020;   4He: 1000020040;
#                  12C: 1000060120;   16O: 1000080160;
#                 63Cu: 1000290630; 107Ag: 1000471070;
#                129Xe: 1000541290;  238U: 1000922380; ... .
#           Cf.
#           1. PDG RPP2024: Phys.Rev.D 110 (2024) 3, 030001
#            https://pdg.lbl.gov/2024/reviews/rpp2024-rev-monte-carlo-numbering.pdf
#           2. PYTHIA 6.4 munual:  JHEP 05 (2006) 026
#            https://arxiv.org/abs/hep-ph/0603175
#           3. PYTHIA 8 online manual:
#            https://pythia.org//latest-manual/ParticleData.html
#           4. The end part of "usu.dat".
#
# i_mode,ifram,nchan (D=6, 1, 10)
#  i_mode: =1, PACIAE low-energy hadronic simulation A-framework (E_CMS < 3 GeV)
#          =2, PYTHIA-like pure hadronic simulation B-framework based on PYTHIA 6
#          =3, PACIAE parton-hadron cascade simulation C-framework based on PYTHIA 6
#          =4, PACIAE experimental mode for pA/Ap simulation D-framework based on PYTHIA 6
#          =5, PYTHIA-like pure hadronic simulation B-framework based on PYTHIA 8
#          =6, PACIAE parton-hadron cascade simulation C-framework based on PYTHIA 8
#          =7, dummy now
#          =8, PYTHIA-like pure hadronic simulation B-framework based on PYTHIA8/Angantyr
#          =9, PACIAE parton-hadron cascade simulation C-framework based on PYTHIA8/Angantyr
#  ifram: to choose the collision system frame type
#         =0, fixed target with the incident momentum +pz (win)
#         =1, collider with CMS energy (win)
#         =2, back-to-back beams with +Z energy_A (win) and -Z energy_B.
#             This option could be used for the fixed-target (energy_B=0) or the
#             asymmetric collision systems like pA/Ap in the Lab frame.
#  nchan: to choose which subset of subprocesses to include in
#         the generration
#         =0, inelastic (INEL)
#         =1, Non-Single Difractive (NSD)
#         =2, Drell-Yan process
#         =3, J/psi production (color singlet)
#         =4, heavy-flavor production
#         =5, direct photon
#         =6, soft only
#         =7, W+/- production
#         =8: PYTHIA default (MSEL=1)
#         =9: Z0 production
#         =10: inelastic, non-diffractive (minimum-bias)
#         <0: -MSEL defined in PYTHIA 6
#        -61: NRQCD charmonium production
#        -62: NRQCD bottomonium production
#        -63: NRQCD onia production (charm- and bottom-)
#     others: requires the user to specify in the program or "pythia6_extra.cfg" /
#                                                            "pythia8_extra.cfg" files.
#
# win(energy_A),energy_B (D=200., 0.)
#  win = incident momentum +pz (GeV) if ifram=0 (fixed target)
#      = cms energy (GeV) if ifram=1 (collider)
#      = (energy_A) energy of +Z beam if ifram=2 of the back-to-back collision
#  energy_B: energy of -Z beam if ifram=2 of the back-to-back collision
#
# bmin,bmax,psno,nmax (D=0., 20., 2, 10)
#  bmin: minimum impact parameters (fm)
#  bmax: maximum impact parameters
#  psno: =0 fixed impact parameter
#        =1 impact parameter is sampled by the systematic sampling method
#        =2 randomly sampled impact parameter
#        =3 for PYTHIA8/Angantyr mode, the original Gaussian sampling method
#           This option will generate weighted events and set a large range of
#            0 < b < 20+ fm automatically.
#  nmax: the number of intervals segmented in [bmin,bmax] when psno=1
#
# kjp21,x_ratio,decpro (D=1, 0.85/0.1, 0.9)
#  kjp21: =0, without hadron rescattering
#         =1, with hadron rescattering via PACIAE
#  x_ratio: PARAM(6), ratio of inel. cross section to total cross
#           section of hadron-hadron scattering, with default value of
#           D=0.85 for the high energy and
#           D=0.1 for the low energy A-framework
#  decpro: is the Delta particle decay probability in low energy A-framework
#
# ispmax,isdmax,iflmax,n_bin_hist,i_y_or_eta (D=20, 7, 2, 40, 1)
#  ispmax: the maximum number of particle KF code to be counted
#  isdmax: the maximum number of statistical distributions
#  iflmax: the maximum number of the kinematic cuts
#  ispmax: the maximum number of bins for histograms
#  i_y_or_eta: select y or eta in partial phase-space statistics (analy.f90)
#            = 0, y
#            = 1, eta
#
# KF_woDecay(i,i=1,ispmax): KF code of particles specified not to decay.
# ispkf(i): KF code of i-th particle to be counted online
#  id/KF code: particle code used in PYTHIA and PACIAE,
#           (list at the end and see details in reference: arXiv:hep-ph/0603175)
# asd(i=1,isdmax): interval of the i-th distribution, i.e. bin width
#  for pp, pbarp, pA(Ap), AB etc.
#      (D=0.35, 0.5, 0.35, 0.5, 25, 0.5, 25)
#      i=1: rapidity distribution (dN/dy v.s. y)
#       =2: invariant transverse momentum distribution (1/pT*dN/dpT v.s. pT)
#       =3: pseudorapidity distribution (dN/deta v.s. eta)
#       =4: transverse mass distribution (1/mT*dN/dmT v.s. mT)
#       =5: event-wise multiplicity distribution (dNev/dmult)
#       =6: transverse momentum distribution (dN/dpT v.s. pT)
#       =7: mean transverse momentum distribution (<pT> v.s. mult)
#  for ep, nu_ep, etc.
#      i=1: Q^2=-q^2 (fq2 in code) distribution
#       =2: W^2 (w21) distribution
#       =3: y (yyl) distribution
#       =4: p_h (pph) distribution
#       =5: z (zl) distribution
#
# afl(j,i,1): lower-boundary of i-th window for j-th particle
# afl(j,i,2): upper-boundary of i-th window for j-th particle
#  for pp, pbarp, pA(Ap), AB etc.
#      i=1, rapidity/pseudorapidity window (D= -1.,1. ) (depends on i_y_or_eta)
#       =2, transverse momentum            (D= 0.,50. )
#  for ep, nu_ep, etc.
#      i=1, Q^2=-q^2 window
#       =2, W^2
#       =3, y
#       =4, p_h (hadron momentum)
#       =5: z
#
# ddt,i_mm (D=0.00001, 2)
#  ddt: minimum distinguishble collision time interval used in 
#       partonic initiation in parini.f90
#  i_mm: only the hadrons below numb(i_mm) (cf. 'filt' in parini.f90)
#        join in updating the hh collision time list (cf. parini.f90).
#        Originally i_mm=2, i.e. only p (proton) and n (neutron) join in
#        updating the collision time list in parton initialization;
#        if i_mm=6, p, n, pbar, nbar, pi+ and pi- will join in updating
#        the collision time list in parton initialization.
#
# iparres, i_inel_proc, i_time_shower, i_diquark (D=0, 1, 0, 1)
#  iparres: =0, consider only the elastic processes in the parton rescattering
#           =1, elastic + inelastic
#  i_inel_proc: = 1, with only light quarks related inelastic processes
#                    in the parton rescattering
#               = 2, with both light and heavy quarks related inel. processes
#  i_time_shower: = 0, without the final state time-like parton shower
#                      in the parton rescattering
#                 =1, performs shower with once branching per parton
#                 =2, performs shower untill the cutoff
#  i_diquark: =0, without diquarks breaking-up before the parton rescattering
#             =1, with
#
# para(7), ttaup, taujp, para(10) (D=1.2, 0., 0.5, 10000.)
#  para(7): proper formation time in rest-frame of particle
#  ttaup: extra factor of the formation time of particles
#         (for protons in parini, for all of hadrons in hadcas)
#  taujp: extra factor of the formation time of J/psi
#  para(10): the largest allowed collision time of the hadronic cascade
#
# i_sigma_AQM, kjp20 (D=1, 1)
#  i_sigma_AQM: = 1, uses input total cross sections of piN, KN, pi+pi,
#                    Jpsi(psi')+N, Jpsi(psi')+N, Jpsi(psi')+pi/rho,
#                    and AQM cross sections for D+N/pi/rho in hadcas.
#                    Ignores the channels which are not well defined.
#               = 2, uses input cross sections of piN, KN, ... ,
#                    AQM cross sections for D+N/pi/rho and the channels
#                    which are not well defined (treated as elastic).
#               = 3, uses AQM cross sections of piN, KN,... and D+N/pi/rho.
#                    Ignores the channels which are not well defined.
#               = 4, uses AQM cross sections of piN, KN, ..., D+N/pi/rho,
#                    and the channels which are not well defined (treated
#                    as elastic).
#  kjp20: choice the cross sections in hadron rescattering (hadcas.f90)
#         =0, energy dependent ones
#         =1, constant cross sections for piN -> K+Sigma/Lambda/Delta,
#             piN -> pi+Delta and NN -> N+Delta in hadcas.
#
# para1_1,para1_2,para(2),para(3),para(4),para(5) (D=0, 40, 25, 21, 10, 2)
#  para1_1: NN total cross section used in constructing the initial collision list
#           <= 0, it will be evaluated in the program (PAXTOT)
#           >  0, accept the input one
#  para1_2: NN total cross section used in hadron cascade
#  para(2): total cross-section of pi-N
#  para(3): total cross-section of K-N
#  para(4): total cross-section of pi-pi
#  para(5): the cross-section of pi-pi -> K-K
#
# para(13),para(14),para(15),para(16) (D=7.2, 4., 14., 8.)
#  para(13): total cross-section of J/psi + N
#  para(14): total cross-section of J/psi + pi/rho
#  para(15): total cross-section of psi' + N
#  para(16): total cross-section of psi' + pi/rho
#
# adj1(i), i=1,40: switches and parameters
# --------------------------------------------------------------------------------
# For PYTHIA 6 new model (PYEVNW):
#     D= 1-10 :  1., 0.47, 0.4,  1000,   1,  0.35,  0.8,  0.35,   0.8, 1.
#        11-20: 0.1,    0,   0,     0,  1.,     1,  1.5,     0,  0.03, 1
#        21-30:   0,   4.,   1,  0.15, 0.4,     1,    0, 10000.,    5, 0
#        31-40:   0,    0,   0,  0.33,   0,     0, 100.,     3., 0.66, 4.
# --------------------------------------------------------------------------------
# For PYTHIA 8 / Angantyr:
#     D= 1-10 :  1., 0.47, 0.4,  1000,    1, 0.68, 0.98,  0.68,  0.98, 1.
#        11-20: 0.1,    0,   0,     0,   1.,    1,  1.5,     0,  0.03, 1
#        21-30:   0,   4.,   1,  0.15,  0.4,    1,    0, 10000.,    5, 0
#        31-40:   0,    0,   0, 0.335, 0.45,    0, 100.,     3., 0.66, 4.
# --------------------------------------------------------------------------------
#     i=1: K factor in parton rescattering; K=0: no parton rescattering.
#       2: alpha_s, effective coupling constant in parton rescattering.
#          Maximum value is set as 1.
#          >  0, constant alpha_s = adj1(2).
#          <= 0, running alpha_s according to Nf=4, Q^2 = s - m1^2 - m2^2, and
#                Lambda_QCD = adj1(25) .
#       3: the regulator (screening masses) / momentum transfer cutoffs
#           introduced in the parton-parton rescattering (parcas).
#          >  0, constant screening.
#          <= 0, dynamic screening. In this case, this parameter will set up
#                a constant effectie temperature T=-adj1(3) for the screening.
#       4: idw, the number of intervals in the numerical integration of the
#          independent Optical Glauber model.
#       5: choice of nuclear shadowing or nPDF for partons in nuclei,
#          available only for the ion-collisions.
#              =0: without nuclear shadowing or nPDF.
#          For PYTHIA 6:
#              =1, Wang's nuclear shadowing (PLB 527 (2002) 85).
#              =2, EPS09 shadowing. (not available temporarily)
#              =other, same as 1
#          For PYTHIA 8:
#              =-1, only Isospin effect.
#              = 1, EPS09, LO nPDF.
#              = 1, EPS09, NLO nPDF.
#              = 1, EPPS16, NLO nPDF.
#          EPS/EPPS shadowing requires for grid files. There is only one default
#              EPS09 LO grid file for Pb208 in PYTHIA 8. One needs add other
#              grid files manually for other nulei or NLO nPDF.
#       6: 'a' in the Lund fragmentation function of the string fragmentation model (PARJ(41) in PYTHIA).
#       7: 'b' in the Lund fragmentation function of the string fragmentation model (PARJ(42) in PYTHIA).
#       8: 'a' in the Lund deexcitation function of the coalescence model. See adj1(29).
#       9: 'b' in the Lund deexcitation function of the coalescence model. See adj1(29).
#       10: K factor PARP(31) in PYTHIA.
#       11: time accuracy used in the hadronic rescattering.
#       12: model for hadronization:
#           =0, string fragmentation.
#           =1, Monte Carlo coalescence model;
#           =2, with gluon splitting & quark deexcitation before parcas and 
#               hadronized by coalescence model (same as adj1(12)=1 + kjp22=2);
#           =3, with gluon splitting & quark deexcitation before parcas and 
#               hadronized by string frafmentation.
#           The subclasses please see "kjp22".
#       13: not used.
#       14: not used.
#       15: string tension of qqbar simple string (D= 1 GeV/fm ~ 0.2 GeV^2).
#       16: allowable number of generations of the quark deexcitation in the
#           Monte Carlo coalescence model.
#           0 = without quark/anti-quark deexcitation.
#           1 = deexcites only the original 1-th q/qbars.
#           2 = same as 1, and deexcites the newly 2-th q/qbars excited from 1-th.
#           3/4/... = ...
#       17: the threshold energy in the deexcitation of energetic quark in
#           the Monte Carlo coalescence model.
#       18: =0, rest partons hadronize by string fragmentation via PYTHIA 6.
#           =1, rest partons hadronize by coalescence.
#           <0, no treatment for the rest partons.
#       19: time accuracy used in the parton rescattering.
#       20: the optional parton-parton cross section in the parton rescattering:
#           =1, small angle and zero-mass approximations for light quarks in
#               elastic parton-parton cross sections with the regulator.
#           =2, full LO-pQCD and massive forms for parton-parton cross sections
#               with the regulator.
#           =3, small angle and zero-mass approximations for light quarks in
#               elastic parton-parton cross sections
#               with cutoffs in the integral limits.
#           =4, full LO-pQCD and massive forms for parton-parton cross sections
#               with cutoffs in the integral limits.
#       21: with or without phase space constraint in the Monte Carlo coalescence model:
#           =0, without phase space constraint,
#           =1, with complete phase space constraint,
#           =2, with spatial phase space constraint only,
#           =3, with momentum phase space constraint only.
#       22: critical value (D=4) of the product of radii in position and momentum
#           phase spaces.
#       23: switch for chiral magnetic effect (CME) induced charge seperation:
#           =0: CME off,
#           =1: CME on.
#       24: the virtuality cut ('tl0' in program) in the time-like radiation in parton
#           rescattering.
#       25: Lambda_QCD used in the parton rescattering.
#       26: selection of random number seed:
#           =0, default PACIAE seed (20240116), can be used for debug;
#           =1, seed from the real-time clock.
#           >1, sets seed as "adj1(26)".
#       27: not used.
#       28: the largest allowed collision time of the partonic cascade
#       29: For coal, sample the deexcited daughter qqbar-pair energy/light-cone
#            momentum fraction z taking from mother
#            =0 : random z in coal
#            =1 : Lund symmetric function, see adj1(8) and adj1(9)
#            =2 : Field-Feynman + Peterson/SLAC, aFF_coal, aPS_c and aPS_b
#            =3 : Lund + Peterson/SLAC (light flavor + heavier)
#            =4 : Lund + Bowler
#            =5 : as = 4, but interpolate for c and b
#           For coal, when using 11, 12, or 13, it is the simple Lund/FF/PS.
#       30: =1, distribute the participant nucleons in overlapping region forcely,
#           =0, without more requirements.
#       31: not used.
#       32: not used.
#       33: not used.
#       34: PARJ(21) (Lund) width of px/py/pT sampling in PYPTDI of the string fragmentation nmodel.
#       35: width of px/py/pT sampling in the coalescence model. See i_pT_coal.
#       36: with or without phenomenological parton energy loss in parton rescattering:
#           =0, without,
#           =1, with. (Do not use this option with the paronic rescattering openning altogether. If so, double-counting!)
#       37: the coefficient in phenomenological parton energy loss.
#       38: pT cut in phenomenological parton energy loss.
#       39: the threshold energy in the gluon splitting in the Monte Carlo coalescence model.
#       40: optional event stopping point
#           =1, after parton initiation,
#           =2, after parton rescattering,
#           =3, after hadronization with coalescence from parton initiation directly,
#           =4, after the entire simulation.
#
# kjp22,kjp23,kjp24,i_color_reconnection,i_tune (D=5, 2, 2, 8, 0)
#  kjp22: optional hadronization subclass
#         For sfm:
#             =1, fragmentation string by string, with the single string 
#                 structure induced variable string tension and PARJ(1) etc.
#             =2, fragmentation string by string, with the multiple string 
#                 interaction induced variable string tension and PARJ(1) etc.
#             =3, fragmentation string by string, with the (single string 
#                 structure + multiple string interaction) induced variable 
#                 string tension and PARJ(1) etc.
#             =4, fragmentation of all strings at once with the 
#                 default string tension and parj(1) etc.
#             =5, fragmentation NN pair by pair with the 
#                 default string tension and parj(1) etc.
#            For PYTHIA 8 only:
#             =6, fragmentation by the Rope Hadronization with Flavour Ropes.
#             =7, fragmentation by the Rope Hadronization with String Shoving.
#             =8, fragmentation by Rope Hadronization with Flavour Ropes 
#                 + String Shoving.
#             =9, Thermodynamical String Fragmentation.
#         For coal:
#             =1, mode 1, with both the gluon splitting and the energetic
#                 quark deexcitation AFTER the partonic rescattering,
#                 via the traversal coalescence.
#             =2, mode 2, with both gluon splitting and the energetic quark
#                 deexcitation BEFORE the partonic rescattering,
#                 via the traversal coalescence.
#             =3, mode 3, as = 1, but with only the quark deexcitation.
#             =4, mode 4, as = 2, but with only the quark deexcitation.
#             =5, as = 2, to keep the consistency of "kjp22" switch.
#             =6, mode 6, as = 1, but via the random coalescence.
#             =7, mode 7, as = 2, but via the random coalescence.
#             =8, mode 8, as = 3, but via the random coalescence.
#             =9, mode 9, as = 4, but via the random coalescence.
#  kjp23: optional model for the calculation of participant nucleon (Npart)
#         in the independent Optical Glauber model
#         =1, geometric model
#         =2, Glauber model
#  kjp24: optional distribution in the independent Optical Glauber model
#         =1, sharp sphere
#         =2, Woods-Saxon
#  i_color_reconnection: MSTP(95) in PYTHIA, selection of color-reconnection model. 
#           =0, no color-reconnection (CR).
#          For PYTHIA 6:
#           'S': Seattle model, 'P': Paquis model.
#           = 1, old cut-and-paste style CR, handled in PYMIHK.
#           = 2, Annealing Type I(no gg loops); hadron-hadron.
#           = 3, Annealing Type I(no gg loops); all beams.
#           = 4, Annealing Type II(gg loops)  ; hadron-hadron.
#           = 5, Annealing Type II(gg loops)  ; all beams.
#           = 6, Annealing Type S             ; hadron-hadron.
#           = 7, Annealing Type S             ; all beams.
#           = 8, Annealing Type P             ; hadron-hadron.
#           = 9, Annealing Type P             ; all beams.
#           =11, Soft Color Interaction (SCI model).
#           =12, SCI without diffraction (no inter-remnant CR).
#           =13, Generalized Area Law (GAL model).
#           =14, GAL without diffraction (no inter-remnant CR).
#          For PYTHIA 8:
#           <15, the MPI-based original PYTHIA 8 scheme (MPI-CR).
#           =15, the new more QCD based scheme(QCD-, QCD-BLC-CR)
#           =16, the new gluon-move model.
#           =17, the SK I e+e- CR model.
#           =18, the SK II e+e- CR model.
#  i_tune: basic PYTHIA parameter set, tune number.
#          =0, "Perugia 2011 Tune" as the basis for PYTHIA6;
#              "Monash 2013 Tune" as the basis for PYTHIA8/Angantyr.
#          >0, correspinding tune "i_tune".
#
# parecc,smadel,cp0,cr0,seco (D=0., 0., 1., 0.2, 0.05)
#  parecc: proportional factor between initial spatial space eccentricity and final
#          momentum space ellipticity
#  smadel: small perpurbation of ellipse from circle for pT
#  cp0,cr0: parameters in the parameterization of the multiple string effect (kjp22= 2 / 3)
#  seco: parameter in the popcorn mechanism for the correction of PARJ(1)
#
# i_deex,n_deex_step,i_pT_coal,i_pT_endpoint (D=1, 1, 1, 0)
#  i_deex: the deexcitation scheme used in the coalescence model
#          = 1, light-cone scheme
#          = 2, energy scheme
#          = 3, logitudinal momentum pz scheme
#  n_deex_step: the number of deexcitation steps per q/qbar
#  i_pT_coal: the pT sampling method of the daughter qqbar pair in coal
#             = 0, 0 pT (collinear)
#             = 1, Gaussian pT (px and py) with width adj1(35)
#             = 2, Exponential pT with width adj1(35)
#  i_pT_endpoint: generation of transverse momentum for endpoint/mother quarks in coal
#                 = 0, no transverse momentum for endpoint quarks
#                 = 1, endpoint quarks obtain transverse momenta like exited qqbars
#
# a_FF,aPS_c,aPS_b,bmrat  (D=0.77, 0.05, 0.005, 0.08)
#  a_FF: parameter for light u, d, s in Field-Feynman function
#  aPS_c: parameter for c in Petersono/SLAC
#  aPS_b: parameter for b in P/S function
#  bmrat: parameter related to the ratio of baryon to meson in the coalescence model
#
# prob_ratio_q (D=1, 1, 0.225, 0, 0, 0)
#  prob_ratio_q: probability ratio u-ubar:d-dbar:s-sbar:c-cbar:b-bbar:t-tbar.
#                used in the gluon splitting and the quark deexcitation.
#
######################        Annotation of usu.dat         ####################
################################################################################



################################################################################
################################################################################
#
#                     List of id/KF codes in program
#
#             1    d                            -1    dbar            
#             2    u                            -2    ubar            
#             3    s                            -3    sbar            
#             4    c                            -4    cbar            
#             5    b                            -5    bbar            
#             6    t                            -6    tbar            
#             7    b'                           -7    b'bar           
#             8    t'                           -8    t'bar           
#            11    e-                          -11    e+              
#            12    nu_e                        -12    nu_ebar         
#            13    mu-                         -13    mu+             
#            14    nu_mu                       -14    nu_mubar        
#            15    tau-                        -15    tau+            
#            16    nu_tau                      -16    nu_taubar       
#            17    tau'-                       -17    tau'+           
#            18    nu'_tau                     -18    nu'_taubar      
#            21    g               
#            22    gamma           
#            23    Z0              
#            24    W+                          -24    W-              
#            25    h0              
#            32    Z'0             
#            33    Z"0             
#            34    W'+                         -34    W'-             
#            35    H0              
#            36    A0              
#            37    H+                          -37    H-              
#            39    Graviton        
#            41    R0                          -41    Rbar0           
#            42    LQ_ue                       -42    LQ_uebar        
#          2101    ud_0                      -2101    ud_0bar         
#          3101    sd_0                      -3101    sd_0bar         
#          3201    su_0                      -3201    su_0bar         
#          4101    cd_0                      -4101    cd_0bar         
#          4201    cu_0                      -4201    cu_0bar         
#          4301    cs_0                      -4301    cs_0bar         
#          5101    bd_0                      -5101    bd_0bar         
#          5201    bu_0                      -5201    bu_0bar         
#          5301    bs_0                      -5301    bs_0bar         
#          5401    bc_0                      -5401    bc_0bar         
#          1103    dd_1                      -1103    dd_1bar         
#          2103    ud_1                      -2103    ud_1bar         
#          2203    uu_1                      -2203    uu_1bar         
#          3103    sd_1                      -3103    sd_1bar         
#          3203    su_1                      -3203    su_1bar         
#          3303    ss_1                      -3303    ss_1bar         
#          4103    cd_1                      -4103    cd_1bar         
#          4203    cu_1                      -4203    cu_1bar         
#          4303    cs_1                      -4303    cs_1bar         
#          4403    cc_1                      -4403    cc_1bar         
#          5103    bd_1                      -5103    bd_1bar         
#          5203    bu_1                      -5203    bu_1bar         
#          5303    bs_1                      -5303    bs_1bar         
#          5403    bc_1                      -5403    bc_1bar         
#          5503    bb_1                      -5503    bb_1bar         
#           111    pi0             
#           211    pi+                        -211    pi-             
#           221    eta             
#           311    K0                         -311    Kbar0           
#           130    K_L0            
#           310    K_S0            
#           321    K+                         -321    K-              
#           331    eta'            
#           411    D+                         -411    D-              
#           421    D0                         -421    Dbar0           
#           431    D_s+                       -431    D_s-            
#           441    eta_c           
#           511    B0                         -511    Bbar0           
#           521    B+                         -521    B-              
#           531    B_s0                       -531    B_sbar0         
#           541    B_c+                       -541    B_c-            
#           551    eta_b           
#           113    rho0            
#           213    rho+                       -213    rho-            
#           223    omega           
#           313    K*0                        -313    K*bar0          
#           323    K*+                        -323    K*-             
#           333    phi             
#           413    D*+                        -413    D*-             
#           423    D*0                        -423    D*bar0          
#           433    D*_s+                      -433    D*_s-           
#           443    J/psi           
#           513    B*0                        -513    B*bar0          
#           523    B*+                        -523    B*-             
#           533    B*_s0                      -533    B*_sbar0        
#           543    B*_c+                      -543    B*_c-           
#           553    Upsilon         
#         10113    b_10            
#         10213    b_1+                     -10213    b_1-            
#         10223    h_1             
#         10313    K_10                     -10313    K_1bar0         
#         10323    K_1+                     -10323    K_1-            
#         10333    h'_1            
#         10413    D_1+                     -10413    D_1-            
#         10423    D_10                     -10423    D_1bar0         
#         10433    D_1s+                    -10433    D_1s-           
#         10443    h_1c            
#         10513    B_10                     -10513    B_1bar0         
#         10523    B_1+                     -10523    B_1-            
#         10533    B_1s0                    -10533    B_1sbar0        
#         10543    B_1c+                    -10543    B_1c-           
#         10553    h_1b            
#         10111    a_00            
#         10211    a_0+                     -10211    a_0-            
#         10221    f_0             
#         10311    K*_00                    -10311    K*_0bar0        
#         10321    K*_0+                    -10321    K*_0-           
#         10331    f'_0            
#         10411    D*_0+                    -10411    D*_0-           
#         10421    D*_00                    -10421    D*_0bar0        
#         10431    D*_0s+                   -10431    D*_0s-          
#         10441    chi_0c          
#         10511    B*_00                    -10511    B*_0bar0        
#         10521    B*_0+                    -10521    B*_0-           
#         10531    B*_0s0                   -10531    B*_0sbar0       
#         10541    B*_0c+                   -10541    B*_0c-          
#         10551    chi_0b          
#         20113    a_10            
#         20213    a_1+                     -20213    a_1-            
#         20223    f_1             
#         20313    K*_10                    -20313    K*_1bar0        
#         20323    K*_1+                    -20323    K*_1-           
#         20333    f'_1            
#         20413    D*_1+                    -20413    D*_1-           
#         20423    D*_10                    -20423    D*_1bar0        
#         20433    D*_1s+                   -20433    D*_1s-          
#         20443    chi_1c          
#         20513    B*_10                    -20513    B*_1bar0        
#         20523    B*_1+                    -20523    B*_1-           
#         20533    B*_1s0                   -20533    B*_1sbar0       
#         20543    B*_1c+                   -20543    B*_1c-          
#         20553    chi_1b          
#           115    a_20            
#           215    a_2+                       -215    a_2-            
#           225    f_2             
#           315    K*_20                      -315    K*_2bar0        
#           325    K*_2+                      -325    K*_2-           
#           335    f'_2            
#           415    D*_2+                      -415    D*_2-           
#           425    D*_20                      -425    D*_2bar0        
#           435    D*_2s+                     -435    D*_2s-          
#           445    chi_2c          
#           515    B*_20                      -515    B*_2bar0        
#           525    B*_2+                      -525    B*_2-           
#           535    B*_2s0                     -535    B*_2sbar0       
#           545    B*_2c+                     -545    B*_2c-          
#           555    chi_2b          
#        100443    psi'            
#        100553    Upsilon'        
#          3122    Lambda0                   -3122    Lambdabar0      
#          4122    Lambda_c+                 -4122    Lambda_cbar-    
#          4132    Xi_c0                     -4132    Xi_cbar0        
#          4232    Xi_c+                     -4232    Xi_cbar-        
#          5122    Lambda_b0                 -5122    Lambda_bbar0    
#          5132    Xi_b-                     -5132    Xi_bbar+        
#          5232    Xi_b0                     -5232    Xi_bbar0        
#          5142    Xi_bc0                    -5142    Xi_bcbar0       
#          5242    Xi_bc+                    -5242    Xi_bcbar-       
#          5342    Omega_bc0                 -5342    Omega_bcbar0    
#          2112    n0                        -2112    nbar0           
#          2212    p+                        -2212    pbar-           
#          3112    Sigma-                    -3112    Sigmabar+       
#          3212    Sigma0                    -3212    Sigmabar0       
#          3222    Sigma+                    -3222    Sigmabar-       
#          3312    Xi-                       -3312    Xibar+          
#          3322    Xi0                       -3322    Xibar0          
#          4112    Sigma_c0                  -4112    Sigma_cbar0     
#          4212    Sigma_c+                  -4212    Sigma_cbar-     
#          4222    Sigma_c++                 -4222    Sigma_cbar--    
#          4312    Xi'_c0                    -4312    Xi'_cbar0       
#          4322    Xi'_c+                    -4322    Xi'_cbar-       
#          4332    Omega_c0                  -4332    Omega_cbar0     
#          4412    Xi_cc+                    -4412    Xi_ccbar-       
#          4422    Xi_cc++                   -4422    Xi_ccbar--      
#          4432    Omega_cc+                 -4432    Omega_ccbar-    
#          5112    Sigma_b-                  -5112    Sigma_bbar+     
#          5212    Sigma_b0                  -5212    Sigma_bbar0     
#          5222    Sigma_b+                  -5222    Sigma_bbar-     
#          5312    Xi'_b-                    -5312    Xi'_bbar+       
#          5322    Xi'_b0                    -5322    Xi'_bbar0       
#          5332    Omega_b-                  -5332    Omega_bbar+     
#          5412    Xi'_bc0                   -5412    Xi'_bcbar0      
#          5422    Xi'_bc+                   -5422    Xi'_bcbar-      
#          5432    Omega'_bc0                -5432    Omega'_bcbar0   
#          5442    Omega_bcc+                -5442    Omega_bccbar-   
#          5512    Xi_bb-                    -5512    Xi_bbbar+       
#          5522    Xi_bb0                    -5522    Xi_bbbar0       
#          5532    Omega_bb-                 -5532    Omega_bbbar+    
#          5542    Omega_bbc0                -5542    Omega_bbcbar0   
#          1114    Delta-                    -1114    Deltabar+       
#          2114    Delta0                    -2114    Deltabar0       
#          2214    Delta+                    -2214    Deltabar-       
#          2224    Delta++                   -2224    Deltabar--      
#          3114    Sigma*-                   -3114    Sigma*bar+      
#          3214    Sigma*0                   -3214    Sigma*bar0      
#          3224    Sigma*+                   -3224    Sigma*bar-      
#          3314    Xi*-                      -3314    Xi*bar+         
#          3324    Xi*0                      -3324    Xi*bar0         
#          3334    Omega-                    -3334    Omegabar+       
#          4114    Sigma*_c0                 -4114    Sigma*_cbar0    
#          4214    Sigma*_c+                 -4214    Sigma*_cbar-    
#          4224    Sigma*_c++                -4224    Sigma*_cbar--   
#          4314    Xi*_c0                    -4314    Xi*_cbar0       
#          4324    Xi*_c+                    -4324    Xi*_cbar-       
#          4334    Omega*_c0                 -4334    Omega*_cbar0    
#          4414    Xi*_cc+                   -4414    Xi*_ccbar-      
#          4424    Xi*_cc++                  -4424    Xi*_ccbar--     
#          4434    Omega*_cc+                -4434    Omega*_ccbar-   
#          4444    Omega*_ccc++              -4444    Omega*_cccbar-  
#          5114    Sigma*_b-                 -5114    Sigma*_bbar+    
#          5214    Sigma*_b0                 -5214    Sigma*_bbar0    
#          5224    Sigma*_b+                 -5224    Sigma*_bbar-    
#          5314    Xi*_b-                    -5314    Xi*_bbar+       
#          5324    Xi*_b0                    -5324    Xi*_bbar0       
#          5334    Omega*_b-                 -5334    Omega*_bbar+    
#          5414    Xi*_bc0                   -5414    Xi*_bcbar0      
#          5424    Xi*_bc+                   -5424    Xi*_bcbar-      
#          5434    Omega*_bc0                -5434    Omega*_bcbar0   
#          5444    Omega*_bcc+               -5444    Omega*_bccbar-  
#          5514    Xi*_bb-                   -5514    Xi*_bbbar+      
#          5524    Xi*_bb0                   -5524    Xi*_bbbar0      
#          5534    Omega*_bb-                -5534    Omega*_bbbar+   
#          5544    Omega*_bbc0               -5544    Omega*_bbcbar0  
#          5554    Omega*_bbb-               -5554    Omega*_bbbbar+  
#       1000001    ~d_L                   -1000001    ~d_Lbar         
#       1000002    ~u_L                   -1000002    ~u_Lbar         
#       1000003    ~s_L                   -1000003    ~s_Lbar         
#       1000004    ~c_L                   -1000004    ~c_Lbar         
#       1000005    ~b_1                   -1000005    ~b_1bar         
#       1000006    ~t_1                   -1000006    ~t_1bar         
#       1000011    ~e_L-                  -1000011    ~e_L+           
#       1000012    ~nu_eL                 -1000012    ~nu_eLbar       
#       1000013    ~mu_L-                 -1000013    ~mu_L+          
#       1000014    ~nu_muL                -1000014    ~nu_muLbar      
#       1000015    ~tau_1-                -1000015    ~tau_1+         
#       1000016    ~nu_tauL               -1000016    ~nu_tauLbar     
#       1000021    ~g              
#       1000022    ~chi_10         
#       1000023    ~chi_20         
#       1000024    ~chi_1+                -1000024    ~chi_1-         
#       1000025    ~chi_30         
#       1000035    ~chi_40         
#       1000037    ~chi_2+                -1000037    ~chi_2-         
#       1000039    ~Gravitino      
#       2000001    ~d_R                   -2000001    ~d_Rbar         
#       2000002    ~u_R                   -2000002    ~u_Rbar         
#       2000003    ~s_R                   -2000003    ~s_Rbar         
#       2000004    ~c_R                   -2000004    ~c_Rbar         
#       2000005    ~b_2                   -2000005    ~b_2bar         
#       2000006    ~t_2                   -2000006    ~t_2bar         
#       2000011    ~e_R-                  -2000011    ~e_R+           
#       2000012    ~nu_eR                 -2000012    ~nu_eRbar       
#       2000013    ~mu_R-                 -2000013    ~mu_R+          
#       2000014    ~nu_muR                -2000014    ~nu_muRbar      
#       2000015    ~tau_2-                -2000015    ~tau_2+         
#       2000016    ~nu_tauR               -2000016    ~nu_tauRbar     
#       3000111    pi_tc0          
#       3000211    pi_tc+                 -3000211    pi_tc-          
#       3000221    pi'_tc0         
#       3000331    eta_tc0         
#       3000113    rho_tc0         
#       3000213    rho_tc+                -3000213    rho_tc-         
#       3000223    omega_tc        
#       3100021    V8_tc           
#       3100111    pi_22_1_tc      
#       3200111    pi_22_8_tc      
#       3100113    rho_11_tc       
#       3200113    rho_12_tc       
#       3300113    rho_21_tc       
#       3400113    rho_22_tc       
#       4000001    d*                     -4000001    d*bar           
#       4000002    u*                     -4000002    u*bar           
#       4000011    e*-                    -4000011    e*bar+          
#       4000012    nu*_e0                 -4000012    nu*_ebar0       
#       5000039    Graviton*       
#       9900012    nu_Re           
#       9900014    nu_Rmu          
#       9900016    nu_Rtau         
#       9900023    Z_R0            
#       9900024    W_R+                   -9900024    W_R-            
#       9900041    H_L++                  -9900041    H_L--           
#       9900042    H_R++                  -9900042    H_R--           
#       9900110    rho_diff0       
#       9900210    pi_diffr+              -9900210    pi_diffr-       
#       9900220    omega_di        
#       9900330    phi_diff        
#       9900440    J/psi_di        
#       9902110    n_diffr0               -9902110    n_diffrbar0     
#       9902210    p_diffr+               -9902210    p_diffrbar-     
#       9900443    cc~[3S18]       
#       9900441    cc~[1S08]       
#       9910441    cc~[3P08]       
#       9900553    bb~[3S18]       
#       9900551    bb~[1S08]       
#       9910551    bb~[3P08]       
#
# Nuclei:
#       100ZZZAAA0 = 1,000,000,000 + Z*10,000 + A*10 + 0.
#    E.g.
#       1000010020 2H (deuteron)          -1000010020 2Hbar (antideuteron)
#       1000020040 4He                    -1000020040 4Hebar          
#       1000030060 6Li                    -1000030060 6Libar          
#       1000040090 9Be                    -1000040090 9Bebar          
#       1000050110 11B                    -1000050110 11Bbar          
#       1000060120 12C                    -1000060120 12Cbar          
#       1000070140 14N                    -1000070140 14Nbar          
#       1000080160 16O                    -1000080160 16Obar          
#       1000130270 27Al                   -1000130270 27Albar         
#       1000140280 28Si                   -1000140280 28Sibar         
#       1000160320 32S                    -1000160320 32Sbar          
#       1000180400 40Ar                   -1000180400 40Arbar         
#       1000200400 40Ca                   -1000200400 40Cabar         
#       1000210450 45Sc                   -1000210450 45Scbar         
#       1000260560 56Fe                   -1000260560 56Febar         
#       1000280580 58Ni                   -1000280580 58Nibar         
#       1000290630 63Cu                   -1000290630 63Cubar         
#       1000360840 84Kr                   -1000360840 84Krbar         
#       1000400960 96Zr  (40, 96)         -1000400960 96Zrbar         
#       1000440960 96Ru  (44, 96)         -1000440960 96Rubar         
#       1000471070 107Ag                  -1000471070 107Agbar        
#       1000541290 129Xe                  -1000541290 129Xebar        
#       1000741840 184W                   -1000741840 184Wbar         
#       1000791970 197Au (79, 197)        -1000791970 197Aubar        
#       1000822080 208Pb (82, 208)        -1000822080 208Pbbar        
#       1000922380 238U                   -1000922380 238Ubar         
#       1000ZZZAAA AAANucleus             -100ZZZAAA0 AAANucleusbar   
USU_ANNO_BLOCKTEXT
echo "${USU_ANNO}" >> usu.dat
####################               usu.dat              ########################
################################################################################



################################################################################
################################################################################
######################             Filenames             #######################
# If you do not change the filenames. just ignore this part.
# For "Makefile".
# Name of PACIAE executable program. (User-defined)
NAME_X="xPaciae40.x"
# Names of PACIAE 4 Fortran source code files.
NAME_MAIN="Paciae"
NAME_F1="Main_40"
NAME_F2="Parini_40"
NAME_F3="Parcas_40"
NAME_F4="Sfm_40"
NAME_F5="Coales_40"
NAME_F6="Hadcas_40"
NAME_F7="Analy_40"
# NAME_PY6="pythia6428"
NAME_PY6="P_40"
# Names of the interface code files.
NAME_F8="Pythia8_fort_interface"
NAME_F9="Pythia8CppInterface"
# Names of PACIAE 4 C++ source code files.
NAME_F10="PaciaeUserHooks"
# Name of PYTHIA 8 Makefile configuration file.
MAKE_CFG="Makefile.inc"
# Name of the standalone averaging executable program and source code files.
NAME_xAVE="xRms_analysis.x"
NAME_AVE="Rms_analysis"
######################             Filenames             #######################
################################################################################
################################################################################



###################################################################################################
###################################################################################################
###############################              Makefile              ################################
read -d "" PACIAE_MAKEFILE << PACIAE_MAKEFILE_BLOCKTEXT
################################################################################
# Makefile is a part of the PACIAE event generator.
# Copyright (C) 2024 PACIAE Group.
# PACIAE is licensed under the GNU GPL v2 or later, see LICENCE for details.
# Open source: https://github.com/ArcsaberHep/PACIAE4
# Author: An-Ke Lei, January 2024 - November 2024.
#
# This is is the Makefile used to complie and build PACIAE program linked with
#  PYTHIA 8 on POSIX systems.
#
# Usage:
#  Type "make -j" to genarate PACIAE running program.
#  Type "make PACIAE -j" to genarate both PACIAE and averaging programs.
#  Type "make clean" to clean temporary files (.o, .log, .out etc.).
#
# Note that you need "make, gfortran and g++" installed on your system.
# For help using the make command please consult the local system documentation,
#  i.e. "man make" or "make --help".
#
#                                               By An-Ke at CCNU on 16/01/2024
#                                  Last updated by An-Ke at UiO  on 11/11/2024
################################################################################

################################################################################
# VARIABLES: Definition of the relevant variables and SHELL commands.
################################################################################

# Sets the shell.
SHELL=/usr/bin/env bash

# Copys "../pythia8311/${MAKE_CFG}" to "./" if "${MAKE_CFG}" does not exist.
ifeq ("\$(wildcard ./${MAKE_CFG})","")
  ifneq ("\$(wildcard ../pythia8311/${MAKE_CFG})","")
    CP_MAKE_INC:=\$(shell cp ../pythia8311/${MAKE_CFG} ./)
  endif
endif

# Includes the configuration from PYTHIA 8.
-include ${MAKE_CFG}

# Checks PYTHIA 8 distribution (use local version first, then installed one).
ifneq ("\$(wildcard ../pythia8311/lib/libpythia8.*)","")
  PREFIX_LIB:=../pythia8311/lib
  PREFIX_INCLUDE:=../pythia8311/include
endif

# PACIAE distribution.
DIR_TOP:=\$(shell pwd)
DIR_INC:=./include
DIR_LIB:=
# DIR_LIB:=./lib
DIR_SRC:=./src
DIR_BIN:=./bin
DIR_OBJ:=./obj
DIR_ETC:=./etc
DIR_DOC:=
# DIR_DOC:=./doc
DIR_LOG:=./log
DIR_SIM:=./sim

# Creates folders and move files.
LOCAL_MKDIR1:=\$(shell mkdir -p \$(DIR_INC) \$(DIR_LIB) \$(DIR_SRC))
LOCAL_MKDIR2:=\$(shell mkdir -p \$(DIR_BIN) \$(DIR_OBJ) \$(DIR_ETC))
LOCAL_MKDIR3:=\$(shell mkdir -p \$(DIR_DOC) \$(DIR_LOG) \$(DIR_SIM))

# Firstly, deltes /bin/${NAME_X}, /bin/${NAME_xAVE}
RM_BIN_X:=\$(shell rm -f ./bin/${NAME_X} ./bin/${NAME_xAVE})

# Moves "./usu.dat" to "./etc" if it exists.
ifneq ("\$(wildcard ./usu.dat)","")
  MV_USU1:=\$(shell mv -f ./usu.dat \$(DIR_ETC)/)
endif
# Moves "./src/usu.dat" to "./etc" if it exists.
ifneq ("\$(wildcard \$(DIR_SRC)/usu.dat)","")
  MV_USU2:=\$(shell mv -f \$(DIR_SRC)/usu.dat \$(DIR_ETC)/)
endif

# Moves "./pythia6_extra.cfg" to "./etc" if it exists.
ifneq ("\$(wildcard ./pythia6_extra.cfg)","")
  MV_PY6CFG1:=\$(shell mv -f ./pythia6_extra.cfg \$(DIR_ETC)/)
endif
# Moves "./src/pythia6_extra.cfg" to "./etc" if it exists.
ifneq ("\$(wildcard \$(DIR_SRC)/pythia6_extra.cfg)","")
  MV_PY6CFG2:=\$(shell mv -f \$(DIR_SRC)/pythia6_extra.cfg \$(DIR_ETC)/)
endif

# Move "./pythia8_extra.cfg" to "./etc" as if it exists.
ifneq ("\$(wildcard ./pythia8_extra.cfg)","")
  MV_PY8CFG1:=\$(shell mv -f ./pythia8_extra.cfg \$(DIR_ETC)/)
endif
# Move "./src/pythia8_extra.cfg" to "./etc" as if it exists.
ifneq ("\$(wildcard \$(DIR_SRC)/pythia8_extra.cfg)","")
  MV_PY8CFG2:=\$(shell mv -f \$(DIR_SRC)/pythia8_extra.cfg \$(DIR_ETC)/)
endif

# Moves source code to "./src" if they exist.
SRC_FILE:= ./*.f* ./*.F* ./*.c* ./*.C*
ifneq ("\$(filter-out ./%.cfg, \$(wildcard \$(SRC_FILE)))","")
  MV_SRC:=\$(shell mv -t \$(DIR_SRC)/ \$(SRC_FILE))
endif

# Moves header files to "./include" if they exist.
INC_FILE:= ./*.h* ./*.H*
ifneq ("\$(wildcard \$(INC_FILE))","")
  MV_INC:=\$(shell mv -t \$(DIR_INC)/ \$(INC_FILE))
endif

# Moves log files to "./log" if they exist.
LOG_FILE:= ./*.log
ifneq ("\$(wildcard \$(LOG_FILE))","")
  MV_LOG:=\$(shell mv -t \$(DIR_LOG)/ \$(LOG_FILE))
endif

# Cleans the log files in "./sim" folder.
SIM_LOG_CLEAN:=\$(shell rm -f \$(DIR_SIM)/*.log)

# Compilation flags. Two different compilers would be used: gfortran and g++.
# Part of them were set in "${MAKE_CFG}".
# C++ compilation flags.
#debug
# CXX_COMMON:=-I\$(PREFIX_INCLUDE) -I\$(DIR_INC) \$(CXX_COMMON) \$(GZIP_LIB) -Wextra -Wuninitialized -fsanitize=address -g
CXX_COMMON:=-I\$(PREFIX_INCLUDE) -I\$(DIR_INC) \$(CXX_COMMON) \$(GZIP_LIB)
PYTHIA8=\$(PREFIX_LIB)/libpythia8\$(LIB_SUFFIX)
# Fortran compilation flags.
GFO:=gfortran
#debug
# GFO_COMMON:=-O0 -W -Wall -Wshadow -g -fdefault-integer-8 -fcheck=all -Wextra -Wuninitialized -fsanitize=address
GFO_COMMON:=-O2 -W -Wall -Wshadow -g -fdefault-integer-8

# Link flags. Note linker is gfortran.
GFO_LINK:=\$(GFO_COMMON)
GFO_LINK+=-I\$(PREFIX_INCLUDE) -I\$(DIR_INC)
GFO_LINK+=-L\$(DIR_LIB) -Wl,-rpath,\$(DIR_LIB)
GFO_LINK+=-L\$(PREFIX_LIB) -Wl,-rpath,\$(PREFIX_LIB) -lpythia8
GFO_LINK+=-ldl -lstdc++
#debug
# GFO_LINK+= -fbacktrace
# GFO_LINK+= -ffpe-trap=invalid,zero,overflow,underflow,denormal,inexact

################################################################################
# RULES: Definition of the rules used to build the PACIAE40.
################################################################################

# PACIAE40 program, i.e. the name of executable file.
TARGET:=${NAME_X}
TARG_AVE:=${NAME_xAVE}
OBJECTS:=\$(DIR_OBJ)/${NAME_MAIN}.o
OBJECTS+=\$(DIR_OBJ)/${NAME_F1}.o \$(DIR_OBJ)/${NAME_F2}.o
OBJECTS+=\$(DIR_OBJ)/${NAME_F3}.o \$(DIR_OBJ)/${NAME_F4}.o
OBJECTS+=\$(DIR_OBJ)/${NAME_F5}.o \$(DIR_OBJ)/${NAME_F6}.o
OBJECTS+=\$(DIR_OBJ)/${NAME_F7}.o \$(DIR_OBJ)/${NAME_PY6}.o
OBJECTS+=\$(DIR_OBJ)/${NAME_F8}.o \$(DIR_OBJ)/${NAME_F9}.o
OBJECTS+=\$(DIR_OBJ)/${NAME_F10}.o
# OBJECTS=\$( wildcard \$(DIR_OBJ)/*.o )
OBJ_AVE:=${NAME_AVE}.o

# Rules without physical targets (secondary expansion for specific rules).
#.SECONDEXPANSION:

.PHONY: all copy_x copy_usu copy_py6cfg copy_py8cfg

# All targets (no default behavior).
all: \$(DIR_BIN)/\$(TARGET) copy_x copy_usu copy_py6cfg copy_py8cfg
	\$(info )
	\$(info PACIAE40 program generation succeeded!)
	\$(info )

# Copys executable file to "./sim".
copy_x: \$(DIR_BIN)/\$(TARGET)
	cp -f \$(DIR_BIN)/\$(TARGET) \$(DIR_SIM)

# Copys "./etc/usu.dat" to "./sim" if it does not exist.
copy_usu: \$(DIR_ETC)/usu.dat
	echo "no" | cp -i \$(DIR_ETC)/usu.dat \$(DIR_SIM)/usu.dat

# Copys "./etc/pythia6_extra.cfg" to "./sim" if it does not exist.
copy_py6cfg: \$(DIR_ETC)/pythia6_extra.cfg
	echo "no" | cp -i \$(DIR_ETC)/pythia6_extra.cfg \$(DIR_SIM)/pythia6_extra.cfg

# Copys "./etc/pythia8_extra.cfg" to "./sim" if it does not exist.
copy_py8cfg: \$(DIR_ETC)/pythia8_extra.cfg
	echo "no" | cp -i \$(DIR_ETC)/pythia8_extra.cfg \$(DIR_SIM)/pythia8_extra.cfg

.PHONY: PACIAE

PACIAE: \$(DIR_BIN)/\$(TARGET) \$(DIR_BIN)/\$(TARG_AVE)
	\$(info )
	\$(info PACIAE40 program generation succeeded!)
	\$(info )

# PYTHIA library.
\$(PYTHIA8):
	\$(error Error: PYTHIA8 must be built, please run "./configure" and \
                "make" in the top PYTHIA8 directory)

# Generate "${NAME_X}" by linking "PACIAE (Fortran 77/90 + C++)" with
#  "${NAME_F8} (Fortran 90/2003)", "${NAME_F9} (C++)",
#  "PYTHIA 6 (FORTRAN 77)" and "PYTHIA 8 (C++)" altogether.
\$(DIR_BIN)/\$(TARGET): \$(OBJECTS)
	\$(GFO) -o \$@ \$^ \$(GFO_LINK)

# Generate "${NAME_MAIN}.o".
\$(DIR_OBJ)/${NAME_MAIN}.o: \$(DIR_SRC)/${NAME_MAIN}.cpp
	\$(CXX) -c -o \$@ \$^ \$(CXX_COMMON)

# Generate "${NAME_F1}.o".
\$(DIR_OBJ)/${NAME_F1}.o: \$(DIR_SRC)/${NAME_F1}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F2}.o".
\$(DIR_OBJ)/${NAME_F2}.o: \$(DIR_SRC)/${NAME_F2}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F3}.o".
\$(DIR_OBJ)/${NAME_F3}.o: \$(DIR_SRC)/${NAME_F3}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F4}.o".
\$(DIR_OBJ)/${NAME_F4}.o: \$(DIR_SRC)/${NAME_F4}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F5}.o".
\$(DIR_OBJ)/${NAME_F5}.o: \$(DIR_SRC)/${NAME_F5}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F6}.o".
\$(DIR_OBJ)/${NAME_F6}.o: \$(DIR_SRC)/${NAME_F6}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F7}.o".
\$(DIR_OBJ)/${NAME_F7}.o: \$(DIR_SRC)/${NAME_F7}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_PY6}.o".
\$(DIR_OBJ)/${NAME_PY6}.o: \$(DIR_SRC)/${NAME_PY6}.f
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F8}.o".
\$(DIR_OBJ)/${NAME_F8}.o: \$(DIR_SRC)/${NAME_F8}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_F9}.o".
\$(DIR_OBJ)/${NAME_F9}.o: \$(DIR_SRC)/${NAME_F9}.cpp
	\$(CXX) -c -o \$@ \$^ \$(CXX_COMMON)

# Generate "${NAME_F10}.o".
\$(DIR_OBJ)/${NAME_F10}.o: \$(DIR_SRC)/${NAME_F10}.cpp
	\$(CXX) -c -o \$@ \$^ \$(CXX_COMMON)

# Plugin libraries.
# lib%.so: %.cc \$(PYTHIA)
# 	\$(CXX) \$< -o \$@ -w \$(CXX_COMMON) \$(CXX_SHARED) -Wl,--no-as-needed

# Generate "${NAME_xAVE}".
\$(DIR_BIN)/\$(TARG_AVE): \$(DIR_OBJ)/\$(OBJ_AVE)
	\$(GFO) -o \$@ \$^ \$(GFO_COMMON)

# Generate "${NAME_AVE}.o".
\$(DIR_OBJ)/\$(OBJ_AVE): \$(DIR_SRC)/${NAME_AVE}.f90
	\$(GFO) -c -o \$@ \$^ \$(GFO_COMMON)

# Clean.
.PHONY: clean
clean:
	rm -f \$(DIR_OBJ)/*.o; rm -f \$(DIR_OBJ)/*.mod;
	rm -f \$(DIR_BIN)/*.x; rm -f \$(DIR_LOG)/*.log;
	rm -f \$(DIR_SIM)/*.o; rm -f \$(DIR_SIM)/*.mod;
	rm -f \$(DIR_SIM)/*.x; rm -f \$(DIR_SIM)/*.log;
	rm -f \$(DIR_SIM)/*.out;
	rm -f \`ls \$(DIR_SIM)/*.dat|egrep -v \$(DIR_SIM)/usu.dat\`;
	rm -f \`ls \$(DIR_SIM)/*.cfg|egrep -v \$(DIR_SIM)/pythia6_extra.cfg\`;
	rm -f \`ls \$(DIR_SIM)/*.cfg|egrep -v \$(DIR_SIM)/pythia8_extra.cfg\`;
	rm -f *.o *.mod *.x *.log *.dat *.cfg;

# Clean "${NAME_AVE}.o" and "${NAME_xAVE}".
.PHONY: clean_rms_analysis
clean_rms_analysis:
	rm -f \$(DIR_OBJ)/${NAME_AVE}.o; rm -f \$(DIR_BIN)/${NAME_xAVE}

# Clean "${NAME_AVE}.o" and "${NAME_xAVE}".
.PHONY: clean_sim
clean_sim:
	rm -f \$(DIR_SIM)/*.o; rm -f \$(DIR_SIM)/*.mod;
	rm -f \$(DIR_SIM)/*.x; rm -f \$(DIR_SIM)/*.log;
	rm -f \$(DIR_SIM)/*.out;
	rm -f \`ls \$(DIR_SIM)/*.dat|egrep -v \$(DIR_SIM)/usu.dat\`;
	rm -f \`ls \$(DIR_SIM)/*.cfg|egrep -v \$(DIR_SIM)/pythia6_extra.cfg\`;
	rm -f \`ls \$(DIR_SIM)/*.cfg|egrep -v \$(DIR_SIM)/pythia8_extra.cfg\`;

# Clean "\$(DIR_LOG)/*.log".
.PHONY: clean_log
clean_log:
	rm -f \$(DIR_LOG)/*.log;

# Clean "bin/*.x".
.PHONY: clean_bin
clean_bin:
	rm -f \$(DIR_BIN)/*.x;

# Clean "obj/*.o obj/*.mod".
.PHONY: clean_obj
clean_obj:
	rm -f \$(DIR_OBJ)/*.o \$(DIR_OBJ)/*.mod;

# Clean "sim directory".
.PHONY: clean_SIM_dir
clean_SIM_dir:
	rm -rI \$(DIR_SIM);
PACIAE_MAKEFILE_BLOCKTEXT
echo -e "${PACIAE_MAKEFILE}" > Makefile
###############################              Makefile              ################################
###################################################################################################
###################################################################################################



################################################################################
################################################################################
####################           Command lines            ########################
#******************************************************************************#
# Compile and build executable files.
echo
sleep 1
# make PACIAE
nohup make PACIAE -j | tee compilation_info.log &
# nohup make PACIAE | tee compilation_info_${current_date_and_time}.log &
wait
mv -f *.log ./log 2>/dev/null || :
if [[ -f "./bin/${NAME_X}" ]]; then
    echo ""
else
    echo -e "\nError: *** file ./bin/${NAME_X} does not exist! Abort!\n"
    exit 1
fi
if [[ -f "./bin/${NAME_xAVE}" ]]; then
    echo ""
else
    echo -e "\nWarning: file ./bin/${NAME_xAVE} does not exist! But continue to execute PACIAE.\n"
fi
#------------------------------------------------------------------------------#
# The simulation will be performed in the "sim" folder.
cd ./sim

#******************************************************************************#
# Total number of events in all program-runnings.
((tot_eve=n_run*n_eve))

#******************************************************************************#
# Folder name of projectile and target. (10 + 10 + 5*6 + 1 = 51)
name_id=(11 -11 12 -12 13 -13 14 -14 15 -15 \
         16 -16 22 111 211 -211 321 -321 130 310 \
         2112 -2112 2212 -2212 1000010020 \
         1000020040 1000030060 1000040090 1000050110 1000060120 \
         1000070140 1000080160 1000130270 1000140280 1000160320 \
         1000180400 1000200400 1000210450 1000260560 1000280580 \
         1000290630 1000360840 1000400960 1000440960 1000471070 \
         1000541290 1000741840 1000791970 1000822080 1000922380)
name_str=(e- e+ nu_e nu_ebar mu- mu+ nu_mu nu_mubar tau- tau+ \
          nu_tau nu_taubar gamma pi0 pi+ pi- K+ K- KL0 KS0 \
          n nbar p pbar 2H \
          4He 6Li 9Be 11B 12C \
          14N 16O 27Al 28Si 32S \
          40Ar 40Ca 45Sc 56Fe 58Ni \
          63Cu 84Kr 96Zr 96Ru 107Ag \
          129Xe 184W 197Au 208Pb 238U)
#------------------------------------------------------------------------------#
# Folder name of projectile.
name_proj="${KF_proj}"
for (( i=0; i<51; ++i ))
do
    if [[ "${KF_proj}" -eq "${name_id[i]}" ]]; then
        name_proj="${name_str[i]}"
    fi
done
#------------------------------------------------------------------------------#
# Folder name of target.
name_targ=${KF_targ}
for (( i=0; i<51; ++i ))
do
    if [[ "${KF_targ}" -eq "${name_id[i]}" ]]; then
        name_targ="${name_str[i]}"
    fi
done
#------------------------------------------------------------------------------#
# Folder name of the collision frame.
name_frame="${i_frame}"
if [[ "${i_frame}" -eq "0" ]]; then
    name_frame="FXT"
elif [[ "${i_frame}" -eq "1" ]]; then
    name_frame="CMS"
elif [[ "${i_frame}" -eq "2" ]]; then
    name_frame="B2B"
fi
#------------------------------------------------------------------------------#
# Creates folders.
if [[ -d "./${name_proj}_${name_targ}_${name_frame}/" ]]; then
    echo "Folder ${name_proj}_${name_targ}_${name_frame} already exists."
else
    mkdir ./${name_proj}_${name_targ}_${name_frame}
fi
cd ./${name_proj}_${name_targ}_${name_frame}

#******************************************************************************#
# iChl: i_channel
# iStg: i_stage
# frame: the name of the simulation framework
if [[ "${i_sim_mode}" -eq "1" ]]; then
    framework_name="A"
elif [[ "${i_sim_mode}" -eq "2" ]]; then
    framework_name="B_PY6"
elif [[ "${i_sim_mode}" -eq "3" ]]; then
    framework_name="C_PY6"
elif [[ "${i_sim_mode}" -eq "4" ]]; then
    framework_name="D"
elif [[ "${i_sim_mode}" -eq "5" ]]; then
    framework_name="B_PY8"
elif [[ "${i_sim_mode}" -eq "6" ]]; then
    framework_name="C_PY8"
# elif [[ "${i_sim_mode}" -eq "7" ]]; then
#     framework_name=""
elif [[ "${i_sim_mode}" -eq "8" ]]; then
    framework_name="B_ANG"
elif [[ "${i_sim_mode}" -eq "9" ]]; then
    framework_name="C_ANG"
else
    framework_name="${i_sim_mode}"
fi
# 900GeV_iChl0_iStg4_frameC
dir_energy="${energy}GeV_iChl${i_channel}_iStg${i_stage}_frame${framework_name}"
if [[ "${i_frame}" -eq "0" ]]; then
    dir_energy="pz${energy}GeV_iChl${i_channel}_iStg${i_stage}_frame${framework_name}"
elif [[ "${i_frame}" -eq "1" ]]; then
    dir_energy="${energy}GeV_iChl${i_channel}_iStg${i_stage}_frame${framework_name}"
elif [[ "${i_frame}" -eq "2" ]]; then
    dir_energy="eA${energy}_eB${energy_B}GeV_iChl${i_channel}_iStg${i_stage}_frame${framework_name}"
fi
if [[ "${i_sim_mode}" -eq "1" ]]; then
    dir_energy="${energy}GeV_frame${framework_name}"
    if [[ "${i_frame}" -eq "0" ]]; then
        dir_energy="pz${energy}GeV_frame${framework_name}"
    elif [[ "${i_frame}" -eq "1" ]]; then
        dir_energy="${energy}GeV_frame${framework_name}"
    elif [[ "${i_frame}" -eq "2" ]]; then
        dir_energy="eA${energy}_eB${energy_B}GeV_frame${framework_name}"
    fi
fi
if [[ -d "./${dir_energy}/" ]]; then
    echo "Folder ${dir_energy} already exists."
else
    mkdir ./${dir_energy}
fi
cd ./${dir_energy}

#******************************************************************************#
str_bp=
str_00=
str_01=
str_02=
str_03=
str_04=
str_05=
str_06=
str_07=
str_08=
str_09=
str_10=
str_11=
str_12=
str_13=
str_14=
str_15=
str_16=
str_17=
str_18=
str_19=
str_20=
dir="./b${b_min}_${b_max}_aL${a_lund}_bL${b_lund}_eDeex${e_deex}_eSplit${e_split}_K${k_PYTHIA}"
# Elementary NN collision
#   A-frame
if [[ "${i_sim_mode}" -eq "1" ]]; then
    str_00=xRatio${x_ratio}
    if [[ "${i_hadcas}" -ne "0" ]]; then
        i_hadcas=1
    fi
    str_01=_iHc${i_hadcas}
else
    # Sfm
    if [[ "${i_hadronization}" -eq "0" || "${i_hadronization}" -eq "3" ]]; then
        str_00="Sfm${i_fragment_mode}"   #
        if [[ "${i_hadronization}" -eq "3" ]]; then
            str_00="Sfm${i_fragment_mode}_deex"   #
        fi
        str_01="_aL${a_lund}"
        str_02="_bL${b_lund}"
        str_03="_sig${pT_width}"
        str_04="_K${k_PYTHIA}"
        str_05="_iCR${i_color_reconnection}"
        str_06="_Kc${k_parcas}"
        # B_PY6, B_PY8, B_ANG
        if [[ "${i_sim_mode}" -eq "2" || \
              "${i_sim_mode}" -eq "5" || "${i_sim_mode}" -eq "8" ]]; then
            str_06=
        fi
        str_07="_iHc${i_hadcas}"
        # str_08=
        # str_09=
        # str_10=
        # str_11=
        # str_12=
        # str_13=
        # str_14=
        # str_15=
        # str_16=
        # str_17=
        # str_18=
        # str_19=
        # str_20=
    # Coal
    elif [[ "${i_hadronization}" -eq "1" || "${i_hadronization}" -eq "2" ]]; then
        # The String-Melting mode.
        if [[ "${i_deex}" -gt "99" ]]; then
            str_00="Coal${i_fragment_mode}_SM"   #
            str_01="_aL${a_lund}"
            str_02="_bL${b_lund}"
            str_03="_sig${pT_width}"
            str_04="_K${k_PYTHIA}"
            str_05="_iCR${i_color_reconnection}"
            str_06="_Kc${k_parcas}"
            # B_PY6, B_PY8, B_ANG
            if [[ "${i_sim_mode}" -eq "2" || \
                "${i_sim_mode}" -eq "5" || "${i_sim_mode}" -eq "8" ]]; then
                str_06=
            fi
            str_07="_iHc${i_hadcas}"
            str_08="_iPc${i_phase_constraint}"
            str_09="_rBM${ratio_B_to_M}"
        else
            str_00="Coal${i_fragment_mode}"   #
            str_01="_iDF${i_deex_function}"
            str_02="_iDx${i_deex}"
            if [[ "${i_deex_function}" -eq "1" ]]; then
                str_03="_aL${a_Lund_coal}"
                str_04="_bL${b_Lund_coal}"
            elif [[ "${i_deex_function}" -eq "2" ]]; then
                str_03="_aFF${a_FF}"
                str_04=
                str_05="_cPS${aPS_c}"
                str_06="_bPS${aPS_b}"
            elif [[ "${i_deex_function}" -eq "3" ]]; then
                str_03="_aL${a_Lund_coal}"
                str_04="_bL${b_Lund_coal}"
                str_05="_cPS${aPS_c}"
                str_06="_bPS${aPS_b}"
            elif [[ "${i_deex_function}" -eq "4" ]]; then
                str_03="_aL${a_Lund_coal}"
                str_04="_bL${b_Lund_coal}"
            elif [[ "${i_deex_function}" -eq "5" ]]; then
                str_03="_aL${a_Lund_coal}"
                str_04="_bL${b_Lund_coal}"
            fi
            # str_07="_ipT${i_pT_coal}"
            str_08="_sig${pT_width_coal}"
            str_09="_eDx${e_deex}"
            str_10="_nDx${n_deex_step}"
            str_11="_eSp${e_split}"
            str_12="_K${k_PYTHIA}"
            # str_13="_iCR${i_color_reconnection}"
            str_14="_iPc${i_phase_constraint}"
            str_15="_Kc${k_parcas}"
            str_16="_iHc${i_hadcas}"
            str_17="_rBM${ratio_B_to_M}"
            str_18=
            # str_19=
            # str_20=
        fi
    fi
fi
# pA, AA collisions
if [[ "${KF_proj}" -gt "1000000000" || "${KF_targ}" -gt "1000000000" ]]; then
    str_bp="b${b_min}_${b_max}_"
fi
dir="./${str_bp}${str_00}${str_01}${str_02}${str_03}${str_04}${str_05}${str_06}${str_07}${str_08}${str_09}${str_10}${str_11}${str_12}${str_13}${str_14}${str_15}${str_16}${str_17}${str_18}${str_19}${str_20}"
#------------------------------------------------------------------------------#
# Creates folders.
if [[ -d "${dir}/" ]]; then
    echo "Folder ${dir} already exists."
else
    mkdir ${dir}
fi
#ls -a
if [[ -d "${dir}/${tot_eve}_events/" ]]; then
    echo "Folder ${tot_eve}_events already exists."
else
    mkdir ${dir}/${tot_eve}_events
fi
cd ${dir}/${tot_eve}_events
echo -e "\nCurrent simulation directory:"
pwd
echo


#************           Inner shell script PACIAE_SIM.sh           ************#
echo "#!/usr/bin/env bash" > PACIAE_SIM.sh
if [[ "${FLAG_SYSTEM}" == "SLURM" ]]; then
    echo "#SBATCH --ntasks=${n_run}   # Number of tasks."   >> PACIAE_SIM.sh
fi
read -d "" PACIAE_SIM_SH << PACIAE_SIM_SH_BLOCKTEXT
${SCHEDULE_SYSTEM}

# For LSF scheduling system:
NP=${n_run}


# Above statements are for normal LINUX system in PC and the scheduling 
#   system on the computing cluster or super-computer.
# Do not delete them but modify them as needed.


# PACIAE_SIM.sh is a part of the PACIAE event generator, and was generated by "PACIAE.sh".
# Copyright (C) 2024 PACIAE Group.
# PACIAE is licensed under the GNU GPL v2 or later, see LICENCE for details.
# Open source: https://github.com/ArcsaberHep/PACIAE4
# Author: An-Ke Lei, January 2024 - November 2024.

# This is a toy SHELL-script to run PACIAE program.

#                                                By An-Ke at CCNU on 14/02/2024
#                                   Last updated by An-Ke at UiO  on 11/11/2024


################################################################################
################################################################################
################################################################################
###                                                                          ###
###   PPPPPPP       AAAAA       CCCCCCC    IIIIIII     AAAAA     EEEEEEEEE   ###
###   P      p     A     A     C       C      I       A     A    E           ###
###   P       p   A       A   C               I      A       A   E           ###
###   P      p    A       A   C               I      A       A   E           ###
###   PPPPPPP     AAAAAAAAA   C               I      AAAAAAAAA   EEEEEEEEE   ###
###   P           A       A   C               I      A       A   E           ###
###   P           A       A   C               I      A       A   E           ###
###   P           A       A    C       C      I      A       A   E           ###
###   P           A       A     CCCCCCC    IIIIIII   A       A   EEEEEEEEE   ###
###                                                                          ###
################################################################################
################################################################################
#                                                                              #
#                                                                              #
################################################################################
#                                                                              #
# This is a universal toy SHELL-script for PACIAE running on the normal LINUX  #
#   system in the personal-computer and task submitting on SLURM (LSF,         #
#   PBS) scheduling systems in the computing cluster and the sunper-computer.  #
#                                                                              #
# It makes the (pseudo-)SPMD (single program, multiple data) possible to       #
#   achieve the (pseudo-)parallel running.                                     #
# Total N events are split up to multiple separate (N/number_of_CPU) events    #
#   and run simultaneously on multiple processors with different input random  #
#   seed based on the real-time clock of the machine.                          #
# This random number generator seed is set in PACIAE internal code (main.f90). #
#                                                                              #
# One needs to note that it's just a "pseudo-parallism". In other words, this  #
#   script just performs PACIAE running one-by-one automatically instead of    #
#   manual runs. One also needs another program to aggregate and average all   #
#   the results needed after the entire PACIAE running finished. A simple      #
#   averaging program, independent of the PACIAE program, "Rms_analysis.f90"   #
#   was provided to do average over the result of "rms.out" the PACIAE         #
#   generated, which gives simple results and reports of the simulation.       #
#                                                                              #
# This script has been tested on WSL/UBUNTU-22.04 on PC, on SLURM on the       #
#   partition), and on LSF on the National SuperComputing Center in Shenzhen   #
#   (NSCCSZ, Gsx_normal partition).                                            #
#                                                                              #
################################################################################
#                                                                              #
# How to use:                                                                  #
#                                                                              #
#   1. First and formost, give this script file "executable permission" by     #
#        typing command "sudo chmod +x PACIAE_SIM.sh" (only once).             #
#                                                                              #
#   2. On SLURM/LSF/PBS scheduling systems in the the computing cluster and    #
#        the super-computer. One needs modify the statements of the settings   #
#        at the beginning of the file (SBATCH, APP_NAME, PBS, ...).            #
#                                                                              #
#   3. Execution.                                                              #
#        3.1 On the normal LINUX, run this script by typing command            #
#              "./PACIAE_SIM.sh".                                              #
#            The more recommended command is                                   #
#              "nohup time ./PACIAE_SIM.sh | tee \$(date "+%Y%m%d%H%M%S").log &"#
#              which stores the screen information to a log file and runs the  #
#              program in the backgroud.                                       #
#       3.2 On SLURM: "sbatch PACIAE_SIM.sh". On LSF: "bsub PACIAE_SIM.sh"     #
#           On PBS: "qsub PACIAE_SIM.sh".                                      #
#                                                                              #
#                                           By An-Ke Lei at CCNU on 14/02/2024 #
#                                                                              #
#                                      Last updated by An-Ke Lei on 17/01/2025 #
################################################################################
################################################################################
################################################################################



# Prompts the current date and time.
echo -e "\nNow is \$(date +"%Y-%m-%d %T")"



################################################################################
################################################################################
####################           Command lines            ########################
#******************************************************************************#
#                                                                              #
# Not required to be modified. Pre-setups for CPU/program-running.
i_cpu=0      # Do not change i_cpu=0. ID od CPU (from 0)
i_run=1      # DO not change i_run=1. Counter for program-running.
i_run_begin=${i_begin}   #Lei_debug
n_run_rms=0
((n_run_rms=${i_begin}+${n_run}-1))   #Lei_debug

# Files checking.
    if [ -f ../../../../../bin/${NAME_X} ]; then
      err_info=
      echo \${err_info}
    else
      err_info="File /bin/${NAME_X} does not exist! Error!"
      echo \${err_info}
      exit 1
    fi

while [ \${i_run} -le ${n_run} ]
do
#     if [ -d "./PACIAE_\${i_run}/" ]; then
#         echo
#     else
#         mkdir ./PACIAE_\${i_run}
#     fi
#     # ls -a
#     cp -f ../../../../../bin/${NAME_X} ./PACIAE_\${i_run}/\${i_run}_${NAME_X}
#     cp -f ../../../../../etc/usu.dat ./PACIAE_\${i_run}/
#     cp -f ../../../../../etc/pythia6_extra.cfg ./PACIAE_\${i_run}/
#     cp -f ../../../../../etc/pythia8_extra.cfg ./PACIAE_\${i_run}/
#     # cp -f ../../../../etc/EPS09* ./PACIAE_\${i_run}/
#     cd ./PACIAE_\${i_run}/
#     # ls -a
#     nohup time ./\${i_run}_${NAME_X} > screen.log &
# # Binds one running task to one CPU.
#     # nohup time taskset -c \${i_cpu} ./\${i_run}_${NAME_X} > screen.log &
#     sleep 0.01
#     cd ..
#     # ls -a

#Lei_debug
    if [ -d "./PACIAE_\${i_run_begin}/" ]; then
        echo
    else
        mkdir ./PACIAE_\${i_run_begin}
    fi
    # ls -a
    cp -f ../../../../../bin/${NAME_X} ./PACIAE_\${i_run_begin}/\${i_run_begin}_${NAME_X}
    cp -f ../../../../../etc/usu.dat ./PACIAE_\${i_run_begin}/
    cp -f ../../../../../etc/pythia6_extra.cfg ./PACIAE_\${i_run_begin}/
    cp -f ../../../../../etc/pythia8_extra.cfg ./PACIAE_\${i_run_begin}/
    # cp -f ../../../../etc/EPS09* ./PACIAE_\${i_run_begin}/
    cd ./PACIAE_\${i_run_begin}/
    # ls -a
    nohup time ./\${i_run_begin}_${NAME_X} > screen.log &
# Binds one running task to one CPU.
    # nohup time taskset -c \${i_cpu} ./\${i_run_begin}_${NAME_X} > screen.log &
    sleep 0.01
    cd ..
    # ls -a

#   echo "PACIAE-\${i_run}"
    echo "PACIAE-\${i_run_begin}"
    ((i_run_begin=i_run_begin+1))
#Lei_debug

    ((i_cpu=i_cpu+1))
    ((i_run=i_run+1))
done
((i_run=i_run-1))

wait
# sleep 30s

if [ -d "./Average/" ]; then
    echo
else
    mkdir ./Average
fi
cp -f ../../../../../bin/${NAME_xAVE} ./Average
cd ./Average

# echo "${n_run},${n_eve}" > input_rms_analysis.dat
echo "\${n_run_rms},${n_eve}" > input_rms_analysis.dat   #Lei_debug
echo "${i_sim_mode},${b_samp}" >> input_rms_analysis.dat
echo "${n_particle_specie},${n_distribution},${n_kine_cut},${n_bin_hist}" >> input_rms_analysis.dat

# # nohup time echo "${n_run}" | ./${NAME_xAVE} > screen.log &
nohup time echo "\${n_run_rms}" | ./${NAME_xAVE} > screen.log &   #Lei_debug
nohup time ./${NAME_xAVE} > screen.log &
wait

cd ..
echo "" >> ./Average/screen.log
for((i=1;i<=${n_run};i++));
do
echo "PACIAE_\${i}:" >> ./Average/screen.log;
cat ./PACIAE_\${i}/nout.out >> ./Average/screen.log;
done

echo
ls -a
echo
echo "PACIAE_SIM-script running ended!"
echo
echo "Current directory:"
pwd
echo
exit 0
####################           Command lines            ########################
################################################################################
################################################################################


################################################################################
################################################################################
################################################################################
#                                                                              #
#                                                                              #
################################################################################
################################################################################
#                                                                              #
#         PPPPPPP       AAAAA      CCCCCCC     IIIIIII     AAAAA     EEEEEEEEE #
#        P      p     A     A    C       C       I       A     A    E          #
#       P       p   A       A   C               I      A       A   E           #
#      P      p    A       A   C               I      A       A   E            #
#     PPPPPPP     AAAAAAAAA   C               I      AAAAAAAAA   EEEEEEEEE     #
#    P           A       A   C               I      A       A   E              #
#   P           A       A   C               I      A       A   E               #
#  P           A       A    C       C      I      A       A   E                #
# P           A       A     CCCCCCC    IIIIIII   A       A   EEEEEEEEE         #
#                                                                              #
################################################################################
################################################################################
################################################################################
PACIAE_SIM_SH_BLOCKTEXT
echo "${PACIAE_SIM_SH}" >> PACIAE_SIM.sh
#************           Inner shell script PACIAE_SIM.sh           ************#

# Excutes the inner shell script to run PACIAE programs.
SUBMIT_COMMAND="sbatch"
if [[ "${FLAG_SYSTEM}" == "LINUX" ]]; then
    nohup time bash PACIAE_SIM.sh > screen.log &
elif [[ "${FLAG_SYSTEM}" == "SLURM" ]]; then
    sbatch PACIAE_SIM.sh
elif [[ "${FLAG_SYSTEM}" == "LSF" ]]; then
    bsub PACIAE_SIM.sh
elif [[ "${FLAG_SYSTEM}" == "PBS" ]]; then
    qsub PACIAE_SIM.sh
fi

cd ../../../../..
echo -e "\nPACIAE-script running ended!"
echo -e "\nUse the \"top\" command to check then quit with 'q'.\n"
ls -a
echo
#Lei_debug
nohup bash memory_monitor.sh &
#Lei_debug
####################           Command lines            ########################
################################################################################
################################################################################



################################################################################
################################################################################
################################################################################
#                                                                              #
#                                                                              #
################################################################################
################################################################################
#                                                                              #
#         PPPPPPP       AAAAA      CCCCCCC     IIIIIII     AAAAA     EEEEEEEEE #
#        P      p     A     A    C       C       I       A     A    E          #
#       P       p   A       A   C               I      A       A   E           #
#      P      p    A       A   C               I      A       A   E            #
#     PPPPPPP     AAAAAAAAA   C               I      AAAAAAAAA   EEEEEEEEE     #
#    P           A       A   C               I      A       A   E              #
#   P           A       A   C               I      A       A   E               #
#  P           A       A    C       C      I      A       A   E                #
# P           A       A     CCCCCCC    IIIIIII   A       A   EEEEEEEEE         #
#                                                                              #
################################################################################
################################################################################
################################################################################